iPhone - MKReverseGeocoder.adminstrativeArea - 获取州名缩写

时间:2010-03-25 18:38:45

标签: iphone mkreversegeocoder

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

谢谢!

2 个答案:

答案 0 :(得分:7)

我还需要将状态字段从MKReverseGeocoder转换为两个字母的缩写,所以我创建了这个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;
    }    
...
}

答案 1 :(得分:3)

没有办法做到这一点。不确定为什么Apple文档会说“CA或California”。

将状态转换为2个字母的名称很容易。只需创建以下内容的plist(表或NSDictionary也可以):http://www.usps.com/ncsc/lookups/usps_abbreviations.html并使用它来查找2个字母的缩写。