如何通过iOS SDK上的给定邮政编码(ZIP)获取国家/地区名称

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

我查看了“核心位置框架”,但是通过邮政编码并find国家/地区名称,它看起来并没有反其道而行之。

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

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

是的,您的解决scheme可以在iOS SDK中find。

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

- (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”)