2012-09-26 45 views

回答

2

是的,它可能叫做reverse geocoding。您需要先导入CoreLocation框架,然后在iOS5(及更高版本)中使用CLGeocoder。对于iOS4和低于其mkreversegeocoder。以下是如何使用CLGeocoder获取地址,只需将它提供给位置对象,剩下的就完成了。

[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 
    ^(NSArray *placemarks, NSError *error) { 

     //Get nearby address 
     CLPlacemark *placemark = [placemarks objectAtIndex:0]; 

     //String to hold address 
     NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; 

     //Print the location to console 
     NSLog(@"I am currently at %@",locatedAt); 

    }]; 

placemarks阵列,你得到的是CLPlacemark对象的实例。 IT让您访问 -

Accessing the Placemark Attributes 
    name property 
    addressDictionary property 
    ISOcountryCode property 
    country property 
    postalCode property 
    administrativeArea property 
    subAdministrativeArea property 
    locality property 
    subLocality property 
    thoroughfare property 
    subThoroughfare property 
    region property 
0

是的。 iOS5及更高版本可以使用CLGeocoder

如果您必须支持以前的操作系统版本,则可以使用MKReverseGeocoder

+0

mkreversegeocoder是旧的过时的API。你应该使用'CLGeocoder',请在有人低估 –

+0

之前更正你的答案啊,谢谢你的评论。我会编辑我的答案。 – barley

0

除了MKReverseGeocoder,我建议你使用google api。我在我的应用程序中使用它,没有崩溃和快速响应。