Reputation: 6849
My App shows the result of a MKLocalSearch
query.
The user can select such a place and say 'I like this place'.
When the user searches again (after closing the App), how can my App know that the user already likes this place?
Is there something in the result that does not depend on the locale (the same at the next search) and unique (not shared by another place at the same location)
let request = MKLocalSearchRequest()
request.region = mapView.region
request.naturalLanguageQuery = query
let search = MKLocalSearch(request: request)
search.start { (response, error) in
// do I know some items in the response?
}
Upvotes: 1
Views: 343
Reputation: 91
I know this thread is old, but thought this would be helpful.
In iOS 18.0 there is a new MKMapItem.Identifier
that seems like it is what you're looking for.
After receiving some search results, you can access the identifier string value of an individual MKMapItem
like this and store it if you like:
if let favoriteIdentifierString = mapItem.identifier?.rawValue {
// Save favorite MKMapItem identifier
}
In a future search you can compare a certain result against the identifier like this:
if mapItem.identifier?.rawValue == favoriteIdentifierString {
// Do something with favorite MKMapItem
}
Or you can use the identifier to search for the map item directly:
if let favoriteIdentifier = MKMapItem.Identifier(rawValue: favoriteIdentifierString) {
let request = MKMapItemRequest(mapItemIdentifier: favoriteIdentifier)
let favoriteMapItem = try await request.mapItem
// Do something with favorite MKMapItem
}
Sources
Upvotes: 1
Reputation: 53
You should get the phone number back as part of the response, which you can use as a unique ID for the location.
Upvotes: 1