当我修复坐标时,iosverseGeocoder 失败?

标签 ios core-location mkreversegeocoder

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

当我使用手写坐标时,反向地理编码失败。但是当我使用从 (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 获取的 - 坐标时,成功。为什么?

最佳答案

当我将您的代码放入测试项目时,它对我来说工作得很好:

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”保存在任何地方(例如在 ivar 或属性中),因此一旦您创建“reverseGeocoder”的函数完成,ARC发布它。

其他一些事情:

如果委托(delegate)方法中有可用的错误参数,您应该使用它们。像这样:

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

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

关于当我修复坐标时,iosverseGeocoder 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18284677/

相关文章:

ios - 我的应用程序进入暂停状态的原因是什么?

ios - 在应用程序处于后台时启动 CLLocationManager 位置更新

iphone - MKReverse Geocoder - 响应语言

iphone - 如何使用 UISearchBar 搜索 MKMapView?

java - 是否有任何现有的 Java 库允许您根据纬度/经度在内存中快速查找邮政编码(奖金、州和城市)?

ios - 无法使用类型为 'String' 的索引下标类型为 'String' 的值

ios - 没有序列化的 AFNetworking

ios - presentViewController 过渡动画

ios像android一样通过短信验证

objective-c - iOS 5 区域监控 : Can new regions be created based on users current coordinates from coreLocation?