Ios 位置服务不返回近距离位置
我正在使用一个代码,在此之后我将发布该代码,根据用户使用自然语言查询在UITextField中键入的内容返回最近的位置。我将所有位置存储在一个数组中,并将该数组传递到PrepareForsgue中的下一个场景(UITableViewController)。然后我使用数组加载所有位置。在模拟器上,它显示了苹果所有的默认位置,这是有意义的。但随后,我在一台真正的iPhone上进行了测试,尽管为该应用程序启用了位置服务,我仍然得到了默认位置。我试了一次又一次,但没有得到实际的结果。它在几周前曾运行过一次,但从那时起就停止了。有什么想法吗?代码如下:Ios 位置服务不返回近距离位置,ios,objective-c,location,Ios,Objective C,Location,我正在使用一个代码,在此之后我将发布该代码,根据用户使用自然语言查询在UITextField中键入的内容返回最近的位置。我将所有位置存储在一个数组中,并将该数组传递到PrepareForsgue中的下一个场景(UITableViewController)。然后我使用数组加载所有位置。在模拟器上,它显示了苹果所有的默认位置,这是有意义的。但随后,我在一台真正的iPhone上进行了测试,尽管为该应用程序启用了位置服务,我仍然得到了默认位置。我试了一次又一次,但没有得到实际的结果。它在几周前曾运行过一
- (void) performSearch {
NSLog(_searchLabel.text);
MKLocalSearchRequest *request =
[[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = _searchLabel.text;
_foundPlaces = [[NSMutableArray alloc] init];
_foundPlacesD = [[NSMutableArray alloc]init];
//NSLog(_place);
MKLocalSearch *search =
[[MKLocalSearch alloc]initWithRequest:request];
[search startWithCompletionHandler:^(MKLocalSearchResponse
*response, NSError *error) {
if (response.mapItems.count == 0)
NSLog(@"No Matches");
else{
for (MKMapItem *item in response.mapItems)
{
NSString *n = item.name;
[_foundPlaces addObject:n];
NSLog(n);
MKDirectionsRequest *dr = [MKDirectionsRequest new];
MKMapItem *source = [MKMapItem mapItemForCurrentLocation];
[dr setSource:source];
[dr setDestination:item];
MKDirections *directions = [[MKDirections alloc]initWithRequest:dr];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *mresponse, NSError *error) {
if(mresponse.routes.count == 0){
NSLog(@"No routes");
}
else{
for(MKRoute *route in mresponse.routes){
CLLocationDistance d = route.distance/1000;
NSString *dText = [NSString stringWithFormat:@"%g kilometers", d];
[_foundPlacesD addObject:dText];
NSLog(dText);
}
}
}];
}
[self performSegueWithIdentifier:@"locationResults" sender:self];
}
}];
}
我想我已经修好了。错误在于segue是在完成之外执行的,而它应该在内部执行