iPhone -- MKReverseGeocoder.adminstrativeArea -- 获取状态缩写

标签 iphone mkreversegeocoder

在 MKReverseGeocoder 的文档中,administrativeArea 属性为您提供用户当前所处的状态,并且在示例中提到它返回状态名称或其缩写。我想知道是否有人知道如何获取缩写而不是完整的州名...除了那个没有提到如何获取的简短示例之外,我找不到任何东西表明这甚至是一种可能性。

谢谢!

最佳答案

我还需要将 MKReverseGeocoder 中的 State 字段转换为两个字母的缩写,因此我创建了这个 plist:

https://github.com/djibouti33/US-State-Abbreviations

这是我的使用方法:

// in my init
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"USStateAbbreviations" ofType:@"plist"];
self.usStateAbbreviations = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

// MKReverseGeocoder delegate method
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {   
... 
    NSString *state = [address objectForKey:@"State"];
    NSString *stateAbbreviation = [self.usStateAbbreviations objectForKey:[state uppercaseString]];
    NSString *stateTarget = state;
    if (stateAbbreviation) {
        stateTarget = stateAbbreviation;
    }    
...
}

关于iPhone -- MKReverseGeocoder.adminstrativeArea -- 获取状态缩写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2518381/

相关文章:

iphone - Apple ZoomingPDFViewer 在第一次缩放之前不允许拖动

iphone - iOS 5 的 JSON 数据

ios - 反向地理编码器自动释放问题

ios - MKReverseGeocoder不返回SubAdministrativeArea

ios - 使用 XCode 在 iphone 4 和 5 屏幕之间按比例调整大小

iphone - 如何使用 XPath 获取根元素?

objective-c - 使用 CLLocationManager 和 MKReverseGeocoder 获取城市名称

ios - Apple 的 CurrentAddress 示例中的 MKReverseGeocoder autorelease/release 问题

iphone - MKReverseGeocoder 服务器返回错误 : 503

iPhone 应用程序在 appStore 中可用的语言