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 に答える