Search code examples
iphoneiosios5geocodingcore-location

iOS CoreLocation CLGeocoder giving incomplete UK postcode


I've got CoreLocation finding me, and then I'm trying to run reverseGeocodeLocation to figure out the postcode. However, I'm getting an incomplete postcode (SO31 4). Normally you'd expect another two characters after the 4. Here's the code I'm using:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation {
    [self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    CLPlacemark *placemark = [placemarks objectAtIndex:0];

    self.postcode.text = placemark.postalCode;
    if (self.postcode.text.length > 0)
        [self.locationManager stopUpdatingLocation];
}];
}

Notably, I also get similar results trying the lat/long on Google Maps API, you can see here: http://maps.googleapis.com/maps/api/geocode/json?latlng=50.87138339,-1.30983213&sensor=true

Ideally I want a full postcode. The only alternative that comes to mind is only using the first four characters but I thought I'd ask here first just incase somebody has a better idea.


Solution

  • They don't have the full UK postcode database so you will only ever get this resolution with the Google API's.

    You need to use a full postcode database and companies like http://www.postcodeanywhere.co.uk/ sell them.