Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 试图调用reverseGeocodeLocation,但程序一直跳过函数调用。有什么想法吗?_Iphone_Ios_Geolocation_Reverse Geocoding_Mapquest - Fatal编程技术网

Iphone 试图调用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

以下是我的代码和我尝试调用reverseGeocodeLocation的完整上下文:

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
的调用会立即返回,远远早于调用完成处理程序之前。您需要更新代码,以便在完成处理程序中创建注释