0
這裏有一段示例代碼:如何從CLPlacemark獲取zipCode,我知道它始終爲空?
[_geoCoder reverseGeocodeLocation:self.locationManager.location // You can pass aLocation here instead
completionHandler:^(NSArray *placemarks, NSError *error) {
dispatch_async(dispatch_get_main_queue(),^ {
// do stuff with placemarks on the main thread
if (placemarks.count == 1) {
CLPlacemark *place = [placemarks objectAtIndex:0];
// NSLog([place postalCode]);
NSString* addressString1 = [place thoroughfare];
addressString1 = [addressString1 stringByAppendingString:[NSString stringWithFormat:@"%@",[place.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey]]];//
NSLog(@"%@",addressString1);// is null ??
NSlog(@"%@",place.postalCode);//is null ??
//[self performSelectorInBackground:@selector(log) withObject:nil];
}
});
}];
@Klass,這段代碼不適用於許多經緯度。它只適用於你通過。有沒有其他方法? – Heena
@Roshni,它在很大程度上取決於蘋果對不同國家的數據。在美國和德國,數據似乎相當不錯。另一種方法是使用Google Maps API及其反向地理編碼器:https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_geocoder – Klaas