Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a local search autocomplete as Apple's native map app does?

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

My appApple Maps app

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?

like image 941
TypingPanda Avatar asked Feb 06 '14 01:02

TypingPanda


3 Answers

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;
like image 155
Ivan Androsenko Avatar answered Nov 02 '22 04:11

Ivan Androsenko


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.

like image 32
augustzf Avatar answered Nov 02 '22 06:11

augustzf


@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!

like image 5
trdavidson Avatar answered Nov 02 '22 04:11

trdavidson