为了避免foursquare或其他本地搜索提供商的API限制,我想使用iOS 6.1中的MKLocalSearch.以下代码:
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);
}
}];
Run Code Online (Sandbox Code Playgroud)
将正确获取并显示指定位置附近的餐馆.如果我localSearchRequest.naturalLanguageQuery改为"酒店",它将获取并显示酒店.这同样适用于"医院","酒吧"等.但是,如果我尝试空字符串,或"","*"或"?" 因为localSearchRequest.naturalLanguageQuery,它没有返回任何结果.
如果我使用foursquare API并将其发送到一个位置,我可以轻松找回包含所有类型的本地商家的场所列表.有没有办法使用MKLocalSearch返回所有场地或本地商家?