iOS反向地理编码问题没有返回placemark.locality的值

时间:2013-04-01 02:28:17

标签: ios iphone geocoding

当我使用CLGeocoder获取当前城市名称时,我遇到了一个非常奇怪的问题。 我用来验证这个的地方是库比蒂诺。我100%确定这不是一个覆盖问题。

NSLog正确地打印了地标,但是当它来到placemark.locality时,那么 它打印(null)。我尝试了其他属性,但它们都有效。我环顾四周,人们似乎有类似的问题,但没有可行的答案。提前感谢您的帮助。

代码如下:

[geoCoder reverseGeocodeLocation:newLocation
                       completionHandler:^(NSArray *placemarks, NSError *error) {  

                           NSLog(@"%@",placemarks);

                           CLPlacemark *placemark =[placemarks objectAtIndex:0];
                           NSLog(@"%@",placemark);
                           NSString *city = placemark.locality;
                           NSLog(@"City:%@", city);
                           if (!city){
                              city = placemark.subAdministrativeArea;
                           }
                           NSLog(@"City:%@", city); 

1 个答案:

答案 0 :(得分:3)

你可以试试吗,

[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            for (CLPlacemark *placemark in placemarks) {
                NSString *city = [placemark locality];
                NSLog(@"%@", city);
            }
}