I have done an implementation by adopting most of the concept from Apple's sample code of the MKlocalSearch from here
Currently for the auto complete, every time user is typing inside the search bar, I am sending a new request where I specified:
MkLocalSearchRequest.naturalLanguageQuery = searchBar.text
MkLocalSearchRequest.region = userlocation.region
But I get totally different set of response from sever comparing to Apple's default map app as shown in the image below
Then I capture the traffic and find that my request goes to https://gsp-ssl.ls.apple.com/search.arpc while Apple's goes to https://gsp-ssl.ls.apple.com/auto_complete.arpc
Is there any way to tune the MkLocalSearchRequest
to get the same set of response objects?
Since iOS 9.3 Apple has provided MKLocalSearchCompleter.
An MKLocalSearchCompleter object takes a partial search string and generates a list of potential completions. You use a search completer object to retrieve auto-complete suggestions for your own map-based search controls.
That's the class that uses https://gsp-ssl.ls.apple.com/auto_complete.arpc
It has quite similar syntax with MkLocalSearchRequest
:
MKLocalSearchCompleter.queryFragment = searchBar.text
MKLocalSearchCompleter.region = userlocation.region
But for results you will need to listen delegate methods:
- (void)completerDidUpdateResults:(MKLocalSearchCompleter *)completer;
MkLocalSearchRequest will not perform auto complete on your search string, perhaps because Apple wants to limit the number of requests from 3rd party apps.
In theory you could reverse-engineer the requests and responses to https://gsp-ssl.ls.apple.com/auto_complete.arpc and then perform those requests yourself, not using MkLocalSearchRequest at all. But that would probably lead to your app being rejected on the App Store.
@TypingPanda - I don't have enough points to comment directly but: beware of using the Google places API! Although perhaps not immediately obvious, Google's terms and conditions state that any visual representation of Google places data needs to occur on a Google Map. Hope everything works out!
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