MKLocalSearch does not find obvious results

My code is almost identical to the following example:

https://github.com/iamamused/Example-MKLocalSearch.git

Here are the important bits:

@interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet MKMapView *ibMapView; @end @implementation ViewController { MKLocalSearch *localSearch; MKLocalSearchResponse *results; } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [localSearch cancel]; MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init]; request.naturalLanguageQuery = searchBar.text; request.region = self.ibMapView.region; localSearch = [[MKLocalSearch alloc] initWithRequest:request]; [localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){ [self.resultTable reloadData]; } } 

It seems reasonable that when Sutter and Mason aka 600 Sutter St. are in the map region where the search for β€œ600 Sutte” will include the obvious result of β€œ600 Sutter St.”. I just can't get this to work. I tried many different streets, and I often get results from the state before getting results that are directly in the map area.

In addition, the β€œ600 Sut” returns irrelevant results, while the β€œ600 Su” returns an error of 4. Did he really not find anything that starts with the β€œ600 Su”?

Am I using this API completely wrong or not intended for what I'm trying to do with it?

Map region for all requests: Map region

600 sutte 600 sutte

600 Su 600 Su

+4
ios ios7 mapkit mklocalsearch
source share
3 answers

I ended up abandoning Apple's local search API and switching to Google. Their API is exactly what I need. He quickly finds relevant results and up to 100 thousand. Requests per day are worthless.

Autocomplete: https://developers.google.com/places/documentation/autocomplete

Details (required for lat, lon): https://developers.google.com/places/documentation/details

Using JSONModel, I ran it in my iOS application after a few hours.

The results are exactly what I was hoping to see:

enter image description here

+3
source share

@borisz - too few points to comment directly. It is IMPORTANT to use the Google Places API in your iOS app. Google declares in its terms that any map displaying data obtained from the Google Places API must be a Google Map. Therefore, if you still want to use your API and search, just make sure that you also use Google Maps, not Apple. Hope this helps - goodluck!

+1
source share

Post it for those who still have similar problems. You should not use MKLocalSearchRequest (), instead use MKLocalSearchCompleter, which gives better results and is used in current Apple Maps.

You can learn how to implement in this answer

0
source share

All Articles