首页 文章

当我修复坐标时,ios reverseGeocoder失败了吗?

提问于
浏览
0
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(27.941761 , -82.171537);

    MKReverseGeocoder *reverseGeocoder =[[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
    NSLog(@"%g",coordinate.latitude);
    NSLog(@"%g",coordinate.longitude);
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];
//????????????????????????????????????????????????????????????????????????

}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark            *)placemark{

NSLog(@"current place is :%@",placemark);
}

当我使用手写坐标时,reverseGeocoding失败 . 但当我使用 - 坐标从(void)locationManager :( CLLocationManager *)管理器didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation,success . 为什么?

1 回答

  • 1

    当我将代码放入测试项目时,它对我来说非常好:

    2013-08-16 23:45:55.966 TestMapApp[11261:a0b] 27.9418
    2013-08-16 23:45:55.967 TestMapApp[11261:a0b] -82.1715
    2013-08-16 23:45:57.831 TestMapApp[11261:a0b] current place is :6015 W Farkas And Turkey Creek Rd, Plant City, FL  33567, United States @ <+27.94176100,-82.17153700> +/- 0.00m
    

    这就是我认为出了问题 . 你正在使用ARC而不是保存你的“ reverseGeocoder " anywhere (like in an ivar or a property), so as soon as the function where you created " reverseGeocoder ”结束,ARC发布它 .

    还有其他一些事情:

    如果在委托方法中有可用的错误参数,则应该使用它们 . 像这样:

    - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
        NSLog(@"MKReverseGeocoder has failed with error %@.", [error localizedDescription]);
    }
    

    最后也是最重要的是,自从iOS 5以来,“ MKReverseGeocoder ”已被弃用 . 在未来的iOS版本中它很有可能会消失 . 您应该尝试找到用于反向地理编码的替代品 .

相关问题