Is it possible to use MKLocalSearch to find all ne

2019-03-18 14:58发布

问题:

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.



标签: ios location