MKLocalSearch not finding obvious results

余生长醉 提交于 2019-11-30 17:59:26

问题


My code is virtually 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 inside the map region searching for "600 Sutte" would include the obvious result "600 Sutter St.". I just can't get that to work. I've tried many different streets and I often get results out of state before I get results that are directly in the map region.

Also, "600 Sut" returns irrelevant results, while "600 Su" returns an error 4. Did it really not find anything that starts with "600 Su"?

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

Map Region for all queries:

600 Sutte

600 Su


回答1:


I ended up giving up on Apple local search API and switching to Google. Their Place API is exactly what I needed. It finds relevant results quickly and up to 100k requests per day doesn't cost anything.

Auto-complete: https://developers.google.com/places/documentation/autocomplete

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

With the help of JSONModel I built it into my iOS app in a few hours.

The results are exactly what I was hoping to see:




回答2:


@borisz - too few points to comment directly..BEWARE of using Google Places API in your IOS app. Google states in their terms and conditions that any map displaying data fetched from Google Places API needs to be a Google Map. So if you still wish to use their API and search, just make sure that you are also using a Google Map and not Apple's native maps. Hope this helps - goodluck!




回答3:


Posting this for those who still have similar problem. You shouldn't 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



来源:https://stackoverflow.com/questions/25027729/mklocalsearch-not-finding-obvious-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!