gpt4 book ai didi

ios - 让 MKLocalSearch 只返回位置

转载 作者:行者123 更新时间:2023-11-29 10:40:17 30 4
gpt4 key购买 nike

我查看了文档,但找不到使用 MKLocalSearch 仅返回区域的方法。例如,我希望搜索在全局范围内搜索城市、城镇、村庄和县,但不返回任何企业或酒店等。这可能吗?

谢谢

D

最佳答案

我认为你可以像这样使用谓词:

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];
}
}];

关于ios - 让 MKLocalSearch 只返回位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24886305/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com