TypingPanda
TypingPanda

Reputation: 1667

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 app Apple 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?

Upvotes: 13

Views: 6258

Answers (3)

Ivan Androsenko
Ivan Androsenko

Reputation: 678

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;

Upvotes: 2

trdavidson
trdavidson

Reputation: 1051

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

Upvotes: 5

augustzf
augustzf

Reputation: 2415

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.

Upvotes: 8

Related Questions