如何通过iOS SDK上的给定邮政编码(ZIP)获取国家/地区名称(How to get Country name by given Postal Code (ZIP) on iOS SDK)

编程入门 行业动态 更新时间:2024-10-26 11:20:02
如何通过iOS SDK上的给定邮政编码(ZIP)获取国家/地区名称(How to get Country name by given Postal Code (ZIP) on iOS SDK)

是否可以通过提供用户的邮政编码来获取国家/地区名称?

我查看了核心位置框架,但考虑到邮政编码并找到国家名称,它看起来并没有相反的方式。

核心位置框架(CoreLocation.framework)为应用程序提供位置和标题信息。 对于位置信息,框架使用板载GPS,小区或Wi-Fi无线电来查找用户当前的经度和纬度。

我希望在iOS SDK上有一个课程,我真的不想使用其中一个Google Maps API

Is it possible to get the country name by giving the postal code of the user?

I looked at the Core Location Framework, but it doesn't look to work the other way around by given the Postal Code and finding the Country name.

The Core Location framework (CoreLocation.framework) provides location and heading information to apps. For location information, the framework uses the onboard GPS, cell, or Wi-Fi radios to find the user’s current longitude and latitude.

I hope there is a class on iOS SDK, I really don't want to use one of the Google Maps APIs

最满意答案

是的,您的解决方案可以在iOS SDK中找到。

将文本字段连接到此操作:

- (IBAction)doSomethingButtonClicked:(id) sender { CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:yourZipCodeGoesHereTextField.text completionHandler:^(NSArray *placemarks, NSError *error) { if(error != nil) { NSLog(@"error from geocoder is %@", [error localizedDescription]); } else { for(CLPlacemark *placemark in placemarks){ NSString *city1 = [placemark locality]; NSLog(@"city is %@",city1); NSLog(@"country is %@",[placemark country]); // you'll see a whole lotta stuff is available // in the placemark object here... NSLog(@"%@",[placemark description]); } } }]; }

我不知道iOS是否支持所有国家的邮政编码,但它肯定适用于英国(例如邮政编码“YO258UH”)和加拿大(“V3H5H1”)

Yes, your solution can be found within the iOS SDK.

Hook up a text field to this action:

- (IBAction)doSomethingButtonClicked:(id) sender { CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:yourZipCodeGoesHereTextField.text completionHandler:^(NSArray *placemarks, NSError *error) { if(error != nil) { NSLog(@"error from geocoder is %@", [error localizedDescription]); } else { for(CLPlacemark *placemark in placemarks){ NSString *city1 = [placemark locality]; NSLog(@"city is %@",city1); NSLog(@"country is %@",[placemark country]); // you'll see a whole lotta stuff is available // in the placemark object here... NSLog(@"%@",[placemark description]); } } }]; }

I don't know if iOS supports postal codes for all countries, but it definitely works for the UK (e.g. postal code of "YO258UH") and Canada ("V3H5H1")

更多推荐

本文发布于:2023-08-01 21:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1365773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮政编码   名称   地区   国家   SDK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!