2012-09-26 94 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。我在我的應用程序中使用它,沒有崩潰和快速響應。