2

I got issue with postal code. I use CLGeocoder and reverseGeocodeLocation:completionHandler: method. Everything looks fine, except that in placemark I don't have postal code. It's nil . I double checked location object and place mark - everything is ok and correct. Can somebody clarify this issue for me? Does geocoder return postalcode only for some countries(USA, UK, etc)? Here is the code:

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");
        }
    }];

2 Answers 2

5

CLGeocoder doesn't return the postalCode for just a City, because there are multiple postalCode.

To obtain the postalCode, you need to be more specific like for example writing the street.

1
  • It get's the street and exact location. But it still doesn't get the postcode
    – htzfun
    Nov 25, 2014 at 13:47
2

The currentLocation that you reverse geocode has a certain horizontal accuracy. If the location uniquely specifies a street, but this street has within the horizontal accuracy 2 postal codes assigned, none might be returned.
So, I suggest to check the currentLocation.horizontalAccuracy property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.