Iphone 试图调用reverseGeocodeLocation,但程序一直跳过函数调用。有什么想法吗?
以下是我的代码和我尝试调用reverseGeocodeLocation的完整上下文:Iphone 试图调用reverseGeocodeLocation,但程序一直跳过函数调用。有什么想法吗?,iphone,ios,geolocation,reverse-geocoding,mapquest,Iphone,Ios,Geolocation,Reverse Geocoding,Mapquest,以下是我的代码和我尝试调用reverseGeocodeLocation的完整上下文: CLLocationCoordinate2D touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView]; CLLocation *destination = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latit
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
CLLocation *destination = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
__block CLGeocoder *destinationPin = [[CLGeocoder alloc] init];
__block NSString *destinationPinName;
[destinationPin reverseGeocodeLocation:destination completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
destinationPinName = [[NSString alloc] initWithString:addressTxt];
}
}];
annotation = [[MQAnnotation alloc] initWithTitle:destinationPinName andCoordinate:touchMapCoordinate];
我在函数入口点、函数中的if块内以及分配注释的函数之后设置了断点。当我到达reverseGeocodeLocation块destinationPin时,它有一个有效值,但我的程序在函数调用后一直直接跳到断点集。知道可能会发生什么吗?执行
reverseGeocodeLocation
是异步的。当后台任务完成时,将调用完成块。所以你看到的是正确的行为。对reverseGeocodeLocation
的调用会立即返回,远远早于调用完成处理程序之前。您需要更新代码,以便在完成处理程序中创建注释。执行reverseGeocodeLocation
是异步完成的。当后台任务完成时,将调用完成块。所以你看到的是正确的行为。对reverseGeocodeLocation
的调用会立即返回,远远早于调用完成处理程序之前。您需要更新代码,以便在完成处理程序中创建注释