是否有可能将您的当前位置逆向地理编码到SDK 3.x上?我需要简单地获取当前位置的邮政编码。我见过的唯一例子是使用CoreLocation,我认为它是在SDK 4之前推出的。逆向地理编码当前位置
回答
您可以使用从3.0到5.0的MKReverseGeocoder。由于5.0 MKReverseGeocoder已折旧并建议使用CLGeocoder。
如果可用,应该使用CLGeocoder。为了能够提取地址信息,您必须包含地址簿框架。
#import <AddressBookUI/AddressBookUI.h>
#import <CoreLocation/CLGeocoder.h>
#import <CoreLocation/CLPlacemark.h>
- (void)reverseGeocodeLocation:(CLLocation *)location
{
CLGeocoder* reverseGeocoder = [[CLGeocoder alloc] init];
if (reverseGeocoder) {
[reverseGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark* placemark = [placemarks firstObject];
if (placemark) {
//Using blocks, get zip code
NSString* zipCode = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
}
}];
}else{
MKReverseGeocoder* rev = [[MKReverseGeocoder alloc] initWithCoordinate:location.coordinate];
rev.delegate = self;//using delegate
[rev start];
//[rev release]; release when appropriate
}
//[reverseGeocoder release];release when appropriate
}
MKReverseGeocoder委托方法:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
//Get zip code
NSString* zipCode = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
}
MKReverseGeocoder和ABPersonAddressZIPKey分别在IOS 9.0弃用。取而代之的是CLPlacemark
的postalcode
属性可以用来获得邮政编码:
NSString * zipCode = placemark.postalCode;
看看http://www.geonames.org。它没有内置到任何SDK中。
您可以使用iPhone手机当前位置扎入这个web服务? – savagenoob 2012-01-02 21:27:03
当然。只要提供它的经度/纬度。 – 2012-01-02 21:29:07
在问题中,有一些关于如何获取纬度和经度的示例代码。 Getting Strange Output in Reverse Geo coder in iphone dev
CoreLocation在SDK 3(自2.0开始)中可用,但CLGeocoder(提供反向地理编码)自5.0版本开始可用。
幸好MapKit框架有MKReverseGeocoder对象。该对象还提供反向地理编码(但在SDK 5中已过时)。
- 1. 逆向地理位置
- 2. Rails通过地理编码器返回当前位置附近的位置
- 3. Facebook位置地理编码
- 4. Xcode地理编码 - 当前地址
- 5. Android:如何根据当前位置获取时间或时区(地理位置/地理编码)
- 6. 尝试使用地理位置打印当前位置地址
- 7. 基于当前用户的地理位置的重定向
- 8. 地理编码 - 获得位置
- 9. 查找iPhone(地理编码)的位置
- 10. 当前位置与地图
- 11. 在tableviewcontroller中反向地理编码位置
- 12. 反向地理编码以获取位置详细信息
- 13. 反向地理编码在日本的一个位置
- 14. 如何在黑莓中使用反向地理编码获取当前位置的州名
- 15. 反向地理编码v3
- 16. J2ME +反向地理编码
- 17. 反向地理编码和本地化
- 18. 谷歌方向从当前位置(LocationServices.FusedLocationApi)
- 19. 方向不显示我的当前位置和目的地
- 20. 地理编码谷歌地图错误的位置
- 21. 谷歌地图API地理编码和位置标记
- 22. 逆向工程汇编代码
- 23. 逆向工程汇编代码到C
- 24. 谷歌地图 - 当前位置
- 25. 谷歌地图上的当前位置
- 26. blackberry gps获取当前位置地址?
- 27. 启动地图当前位置
- 28. 谷歌地图当前位置Swift
- 29. Android - 可靠地获取当前位置
- 30. 当前用户位置的2D地图
工作完美,谢谢! – RyanG 2012-08-07 15:20:04