2013-08-17 45 views
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成功。为什么?ios reverseGeocoder失败,当我固定坐标?

回答

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”,因此只要您创建“reverseGeocoder”的功能完成,ARC就会发布它。

一对夫妇的其他东西:

如果在委托方法提供给你一个错误的参数,你应该使他们的使用。就像这样:

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

而且最后&最重要的是,“MKReverseGeocoder”已经过时了,因为iOS的5有一个很好的机会,它会在iOS中的未来版本中消失。您应该尝试找到用于反向地理编码的替代品。