所以我看了Apple的示例代码以获取用户位置。这对我来说很好,它的显示位置也是正确的。
现在我想在我创建的名为“zipCode”的文本字段中显示邮政编码。我该怎么做?
尝试:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations objectAtIndex:0];
NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
zipCode.text = self.placemark.postalCode;
}
但那没用。
答案 0 :(得分:1)
您需要使用reverseGeocodeLocation,例如:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations objectAtIndex:0];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:
^(NSArray* placemarks, NSError* error){
if ([placemarks count] > 0)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
zipCode.text = placemark.postalCode;
}
}];
}
请记住导入CoreLocation.framework
答案 1 :(得分:0)
如果您想要有关地图上某个位置的隐蔽信息,则必须使用反向地理编码 全部写成here。