【问题标题】:IOS: reverse geocodign provinceIOS:反向地理编码省
【发布时间】:2012-06-22 09:05:26
【问题描述】:

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

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

}

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

【问题讨论】:

    标签: ios xcode reverse-geocoding


    【解决方案1】:

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

    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
    Street。
    适用于 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
    国家代码。支持的值列在“国家代码”中。
    适用于 iOS 2.0 和 稍后。
    在 ABPerson.h 中声明。

    很遗憾,没有一个省。

    【讨论】:

    • 没有办法获得省份?
    • 可能没有。我认为省只是某些国家/地区的特定国家领土,因此不包括在内,但可以将其从州中取出,但我不确定它是否填满,试一试...跨度>
    【解决方案2】:

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

    [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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2012-08-30
      相关资源
      最近更新 更多