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;
                              ];
                          }
                      }];
    }
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top