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

发布于 2024-08-26 05:22:40 字数 166 浏览 3 评论 0原文

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

谢谢!

In the documentation for MKReverseGeocoder, the administrativeArea property gives you the current state the user is in, and it mentions in an example that it returns EITHER the state name OR its abbreviation. I am wondering if anyone knows how to get the abbreviation instead of the full state name...I have been able to find nothing that shows this is even a possibility besides that brief example that doesn't mention HOW.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温暖的光 2024-09-02 05:22:40

我还需要将 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;
    }    
...
}

I also needed to convert the State field from MKReverseGeocoder into a two letter abbreviation, so I created this plist:

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

Here's how I use it:

// 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;
    }    
...
}
满天都是小星星 2024-09-02 05:22:40

没有办法做到这一点。不知道为什么苹果文档说“CA 或 California”。

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

There is no way to do this. Not sure why the Apple docs say "CA or California".

It's easy to convert state to 2 letter name. Just create a plist (table, or NSDictionary works too) of the following: http://www.usps.com/ncsc/lookups/usps_abbreviations.html and use that to look up the 2 letter abbreviations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文