我查看了文档,但找不到使用MKLocalSearch返回区域的方法。例如,我希望搜索能够在全球范围内搜索城市,城镇和村庄。县,但没有返回任何企业或酒店等。这可能吗?
由于
d
答案 0 :(得分:2)
我认为你可以使用这样的谓词:
NSPredicate *noBusiness = [NSPredicate predicateWithFormat:@"business.uID == 0"];
NSMutableArray *itemsWithoutBusinesses = [response.mapItems mutableCopy];
[itemsWithoutBusinesses filterUsingPredicate:noBusiness];
示例本地搜索代码也在添加,这将解决您的问题。
-(void)issueLocalSearchLookup:(NSString *)searchString {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.location.coordinate, 30000, 30000);
self.localSearchRequest = [[MKLocalSearchRequest alloc] init];
self.localSearchRequest.region = region;
self.localSearchRequest.naturalLanguageQuery = searchString;
self.localSearch = [[MKLocalSearch alloc] initWithRequest:self.localSearchRequest];
[self.localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
if(error){
NSLog(@"LocalSearch failed with error: %@", error);
return;
} else {
for(MKMapItem *mapItem in response.mapItems){
[self.data addObject:mapItem];
}
[self.searchDisplayController.searchResultsTableView reloadData];
}
}];
}
答案 1 :(得分:0)
根据您的要求更改addressDictionary的关键参数。
for(MKMapItem *mapItem in response.mapItems)
{
NSLog(@"%@",mapItem.placemark.addressDictionary[@"Street"]);
}