在 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/