是否有可能将您的当前位置逆向地理编码到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. 基于当前位置的地理编码结果
- 3. 通过地理编码器获取当前位置。 Rails
- 4. Rails通过地理编码器返回当前位置附近的位置
- 5. Facebook位置地理编码
- 6. Xcode地理编码 - 当前地址
- 7. Android:如何根据当前位置获取时间或时区(地理位置/地理编码)
- 8. 尝试使用地理位置打印当前位置地址
- 9. 基于当前用户的地理位置的重定向
- 10. 客户端逆向地理编码(Google Maps V3 API)
- 11. Rails - 如何使用地理编码器通过IP获取当前位置
- 12. 地理编码 - 获得位置
- 13. 查找iPhone(地理编码)的位置
- 14. 地理位置编码错误
- 15. 邮政编码地理位置
- 16. CLGeocoder前进地理编码倍数位置
- 17. 反向地理编码位置:比范围
- 18. 反向地理编码没有给予正确的位置
- 19. CLGeocoder给定位置的反向地理编码
- 20. 反向地理编码:如何获得准确位置
- 21. 在tableviewcontroller中反向地理编码位置
- 22. 反向地理编码在日本的一个位置
- 23. 反向地理编码就是我相反的位置
- 24. 反向地理编码以获取位置详细信息
- 25. 使用当前位置作为变量的地理位置
- 26. Arcgis地图当前位置
- 27. 当前位置与地图
- 28. 地理编码非地址:地理位置
- 29. 如何在黑莓中使用反向地理编码获取当前位置的州名
- 30. 从给定坐标(不是当前位置,但手动提供)反向地理编码
工作完美,谢谢! – RyanG 2012-08-07 15:20:04