2012-06-22 25 views
0

我有這樣的代碼來扭轉地理編碼和它IOS:反向geocodign省

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    MKPlacemark * myPlacemark = placemark; 
    // with the placemark you can now retrieve the city name 
    NSString *region = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressStateKey]; 
    NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey]; 
    NSString *address = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressStreetKey]; 
    NSLog(@"region:%@", region); 
    NSLog(@"city:%@", city); 
    NSLog(@"address:%@", address); 

} 

它做工精細的工作,但我不能有「省」 ......什麼是獲得全省的方式嗎?

回答

0

這些是地址字典中的所有鍵:

const ABPropertyID kABPersonAddressProperty; 
const CFStringRef kABPersonAddressStreetKey; 
const CFStringRef kABPersonAddressCityKey; 
const CFStringRef kABPersonAddressStateKey; 
const CFStringRef kABPersonAddressZIPKey; 
const CFStringRef kABPersonAddressCountryKey; 
const CFStringRef kABPersonAddressCountryCodeKey; 

常量
kABPersonAddressProperty
標識符地址多值屬性。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressStreetKey
Street。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressCityKey城市。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressStateKey
狀態。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressZIPKey
郵政編碼。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressCountryKey
國家。
Available in iOS 2.0及更高版本。
在ABPerson.h中聲明。

kABPersonAddressCountryCodeKey
國家代碼。受支持的值在「國家代碼」中列出。
稍後可在iOS 2.0和 中使用。
在ABPerson.h中聲明。

不幸的是,沒有一個省。

+0

並且沒有辦法獲得省? – CrazyDev

+0

也許沒有。我認爲省只是一些國家的特定國家的領土,因此它不包括在內,但是可以從國家拿出來,但我不確定它是否填滿了,試試看...... – graver

0

在我的代碼中,我有以下方法來獲取地址和地名。 省州或administrativeArea

[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
     if(placemarks.count){ 

     NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary]; 
     addressLabel.Text = [dictionary valueForKey:@"Street"]; 
     cityLabel.Text = [dictionary valueForKey:@"City"]; 
     stateLabel.Text = [dictionary valueForKey:@"State"]; 
     zipCodeLabel.Text = [dictionary valueForKey:@"ZIP"]; 
     countryLabel.text = [dictionary valueForKey:@"Country"]; 
     countryCodeLabel.text = [dictionary valueForKey:@"CountryCode"]; 


     placeNameLabel.text = [placemarks[0] name]; 
     addressNumberLabel.text = [placemarks[0] subThoroughfare]; 
     addressLabel.text = [placemarks[0] thoroughfare]; 
     neighborhoodLabel.text = [placemarks[0] subLocality]; 
     cityLabel.text = [placemarks[0] locality]; 
     countyLabel.text = [placemarks[0] subAdministrativeArea]; 
     stateLabel.text = [placemarks[0] administrativeArea]; 
     zipCodeLabel.text = [placemarks[0] postalCode]; 
     countryLabel.text = [placemarks[0] country]; 
     countryCodeLabel.text = [placemarks[0] ISOcountryCode]; 
     inlandWaterLabel.text = [placemarks[0] inlandWater]; 
     oceanLabel.text = [placemarks[0] ocean]; 
    } 
}]; 

你可以試試我的開源項目。獲得地點標記很容易。 Device-Detailshttps://github.com/robert-yi-jones/Device-Details