문제

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