Is it possible to use MKLocalSearch to find all nearby businesses?

我的未来我决定 提交于 2019-12-20 18:51:32

问题


In order to avoid the API limits of foursquare or one of the other local search providers, I would like to use MKLocalSearch from iOS 6.1. The following code:

MKLocalSearchRequest *localSearchRequest = [[MKLocalSearchRequest alloc] init];
MKCoordinateRegion localSearchRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake([theLocationChange.latitude floatValue], [theLocationChange.longitude floatValue]), 500.0f, 500.0f);
localSearchRequest.naturalLanguageQuery = @"restaurants";
localSearchRequest.region = localSearchRegion;
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:localSearchRequest];

[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
{
    if (error)
    {
        NSLog([error localizedDescription]);
    }
    for (MKMapItem* mapItem in response.mapItems)
    {
        NSLog(@"mapitem name is: %@",mapItem.name);
    }

}];

will correctly fetch and display restaurants near the specified location. If I change localSearchRequest.naturalLanguageQuery to "hotels", it will fetch and display hotels. The same applies for "hospitals", "bars", etc. If, however, I try an empty string, or " ", "*", or "?" for localSearchRequest.naturalLanguageQuery, it returns no results.

If I use the foursquare API and send it a location, I can easily get back a list of venues that includes local businesses of all types. Is there a way to use MKLocalSearch to return all venues or local businesses?


回答1:


Apple documentation says that localSearchRequest.naturalLanguageQuery to be considered as natural Language query which means, you can type in anything and get the related results to your query. But Apples Maps database may not be returning the values as you expect.



来源:https://stackoverflow.com/questions/16995834/is-it-possible-to-use-mklocalsearch-to-find-all-nearby-businesses

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