2014-11-25 45 views
1

我遇到了郵政編碼問題。我使用CLGeocoderreverseGeocodeLocation:completionHandler:方法。一切看起來都很好,除了在地標上我沒有郵政編碼。它是nil。我加倍檢查位置對象並放置標記 - 一切正常,正確。有人能爲我澄清這個問題嗎?地理編碼器是否僅爲某些國​​家(美國,英國等)返回郵政編碼?這裏是代碼:Geocoded不返回郵政編碼

CLGeocoder *geocoder = [[CLGeocoder alloc] init] ; 
CLLocation *currentLocation = self.locationManager.location; 
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
     if (!error) { 
      CLPlacemark *placemark = [placemarks firstObject]; 
      if (placemark.postalCode) { 
       NSLog(@"%@", placemark.postalCode); 
      } else { 
       NSLog(@"No postal code"); 
      } 
     } else { 
      NSLog(@"Error occurred"); 
     } 
    }]; 

回答

4

CLGeocoder不會爲一個城市返回postalCode,因爲有多個postalCode。

要獲得郵政編碼,您需要更具體,例如寫作街道。

+0

它得到了街道和確切位置。但它仍然沒有得到郵政編碼 – htzfun 2014-11-25 13:47:58

1

您反向地理編碼的currentLocation具有一定的水平精度。如果該地點唯一指定了一條街道,但該街道在水平精度範圍內已分配2個郵政編碼,則不可能返回任何郵政編碼。
所以,我建議檢查currentLocation.horizontalAccuracy屬性。

相關問題