Apple introduced the MKLocalSearchCompleter and MKLocalSearchCompletion in iOS 9.3. I am trying to implement it. It becomes a two step process 1) enter partial term -> full search text is generated. 2) User selects one of these to search for the actual location.
The question is if I search for 200 townsend, it gives me a list of locations but it is till treated as suggestion by the app. How can we identify if it is a MKMampItem or suggestion?
One way to do this is to initialize a MKLocalSearchRequest
with a MKLocalSearchCompletion
.
let request = MKLocalSearchRequest(completion: completion)
You can then initialize a MKLocalSearch
with a MKLocalSearchRequest
.
let search = MKLocalSearch(request: request)
You can then start the search
which has a completion handler with a MKLocalSearchResponse?
and NSError?
. The MKLocalSearchResponse?
will have an array of MKMapItem
's.
Full example:
let request = MKLocalSearchRequest(completion: completion)
let search = MKLocalSearch(request: request)
search.startWithCompletionHandler { (response: MKLocalSearchResponse?, error: NSError?) in
if let error = error {
// do something with "error"
}
else if let mapItems = response?.mapItems {
// do something with "mapItems"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With