是否有可能將您的當前位置逆向地理編碼到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