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 回答
当我将代码放入测试项目时,它对我来说非常好:
这就是我认为出了问题 . 你正在使用ARC而不是保存你的“
reverseGeocoder
" anywhere (like in an ivar or a property), so as soon as the function where you created "reverseGeocoder
”结束,ARC发布它 .还有其他一些事情:
如果在委托方法中有可用的错误参数,则应该使用它们 . 像这样:
最后也是最重要的是,自从iOS 5以来,“
MKReverseGeocoder
”已被弃用 . 在未来的iOS版本中它很有可能会消失 . 您应该尝试找到用于反向地理编码的替代品 .