Question

I have used reverseGeocodeLocation to get zip code from, however, it returns only five digits, example: "94112".
But here in Brazil, we have zip code with eight digits, example "08750630", but the aftermath is "08750".

How to solve this? is it possible?

My Code:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {

    CLLocationCoordinate2D coords = newLocation.coordinate;

    lastLat = coords.latitude;
    lastLng = coords.longitude;

    CLGeocoder *reverse = [[CLGeocoder alloc] init];
    CLLocation *location = [[CLLocation alloc] initWithLatitude:coords.latitude
                                                      longitude:coords.longitude];
    lastAccuracy = newLocation.horizontalAccuracy;
    lblAccuracy.text = [NSString stringWithFormat:@"%f",lastAccuracy];

    if(lastAccuracy <= 10)
    {
        [reverse reverseGeocodeLocation:location
                      completionHandler:^(NSArray *placemarks, NSError *error) {
                          if ([placemarks count] > 0) {
                              CLPlacemark *place = [placemarks objectAtIndex:0];
                              strCEP = place.postalCode;
                              strLastSubLocation = place.subLocality;
                              strLastLocation = place.locality;
                              strEndereco = place.thoroughfare;
                              lblEndereco.text = strEndereco;
                              ];
                          }
                      }];
    }
Was it helpful?

Solution

It's possible to get the full postal code number accessing the addressDictionary property from CLPlacemark.

In this NSDictionary we can get the information we need in the values from the keys: ZIP and PostCodeExtension.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top