在 MKReverseGeocoder 的文档中,administrationArea 属性为您提供了用户当前所处的状态,并在示例中提到它返回状态名称或其缩写。我想知道是否有人知道如何获得缩写而不是完整的州名……除了没有提到如何的简短示例之外,我找不到任何东西表明这甚至是一种可能性。
谢谢!
在 MKReverseGeocoder 的文档中,administrationArea 属性为您提供了用户当前所处的状态,并在示例中提到它返回状态名称或其缩写。我想知道是否有人知道如何获得缩写而不是完整的州名……除了没有提到如何的简短示例之外,我找不到任何东西表明这甚至是一种可能性。
谢谢!
我还需要将 MKReverseGeocoder 中的 State 字段转换为两个字母的缩写,所以我创建了这个 plist:
https://github.com/djibouti33/US-State-Abbreviations
这是我如何使用它:
// 在我的初始化中
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"USStateAbbreviations" ofType:@"plist"];
self.usStateAbbreviations = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
// MKReverseGeocoder 委托方法
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
...
NSString *state = [address objectForKey:@"State"];
NSString *stateAbbreviation = [self.usStateAbbreviations objectForKey:[state uppercaseString]];
NSString *stateTarget = 状态;
如果(状态缩写){
stateTarget = stateAbbreviation;
}
...
}
没有办法做到这一点。不知道为什么 Apple 文档会说“CA 或 California”。
将状态转换为 2 个字母名称很容易。只需创建以下内容的 plist(表格或 NSDictionary 也适用):http ://www.usps.com/ncsc/lookups/usps_abbreviations.html并使用它来查找 2 个字母的缩写。