0

我有这个代码来反向地理编码,它可以工作

- (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);

}

它工作正常,但我无法拥有“省”......获得省份的方法是什么?

4

2 回答 2

0

这些是地址字典的所有键:

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

常量
kABPersonAddressProperty
地址多值属性的标识符。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressStreetKey
街道。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressCityKey城市。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressStateKey
状态。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressZIPKey
邮政编码。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressCountryKey
国家。
在 iOS 2.0 及更高版本中可用。
在 ABPerson.h 中声明。

kABPersonAddressCountryCodeKey
国家代码。支持的值列在“国家代码”中。<br/> 适用于 iOS 2.0 及更高版本。
在 ABPerson.h 中声明。

不幸的是,没有一个省。

于 2012-06-22T09:17:35.587 回答
0

在我的代码中,我有以下方法来获取地址和地名。省是州或行政区

[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];
    }
}];

你可以试试我的开源项目。很容易获得地标。设备详细信息 https://github.com/robert-yi-jones/Device-Details

于 2013-09-03T00:22:34.787 回答