Objective c Zipcode未显示在reverseGeocode中

Objective c Zipcode未显示在reverseGeocode中,objective-c,reverse-geocoding,Objective C,Reverse Geocoding,我正在尝试获取用户当前位置的ZipCode。 它在美国运作良好,但其他国家也有一些问题 if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [self.locationManager requestAlwaysAuthorization]; } _coder = [[CLGeocoder alloc] init]; _locationManager = [[CLLo

我正在尝试获取用户当前位置的ZipCode。 它在美国运作良好,但其他国家也有一些问题

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

        [self.locationManager requestAlwaysAuthorization];
    }

    _coder = [[CLGeocoder alloc] init];
    _locationManager = [[CLLocationManager alloc]init];
    _locationManager.delegate = self;
    [_locationManager startUpdatingLocation];

        //Block address
    [_coder reverseGeocodeLocation: _locationManager.location completionHandler:
     ^(NSArray *placemarks, NSError *error) {

             //Get address
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
        if(placemark.addressDictionary == NULL){
                 NSLog(@"Error in getting address");
         }else{
 NSLog(@"Placemark array: %@",placemark.addressDictionary );
 NSString *locateaddress;
                 //String to address
if(self.switcher.on){
            locateaddress = [placemark.addressDictionary   valueForKey:@"ZIP"];
 if (!locateaddress || [locateaddress isKindOfClass:[NSNull class]]){

            }
             }else{
                 locateaddress = zipCodeString;
             }
行NSLog(@“Placemark array…)正在返回此

> Placemark array: {
>     City = Jerusalem;
>     Country = Israel;
>     CountryCode = IL;
>     FormattedAddressLines =     (
>         "to begin south",
>         Jerusalem,
>         Israel
>     );
>     Name = "to begin south";
>     State = Jerusalem;
>     Street = "to begin south";
>     Thoroughfare = "to begin south"; }
那么1)为什么没有邮政编码或邮政编码选项
2) 如何从这些信息中获取邮政编码?

试试这个。可能会对您有所帮助

//Get Location
-(void)updateLocation:(CLLocation *)newLocation fromLocation:(CLLocation  *)oldLocation
{
    self.currentCLLocation = newLocation;
    [self getCurrentAddress];
}

//Get address using location.
-(void)getCurrentAddress
{

    //Geocoding Block
    CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
    CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:[self.sharedLat doubleValue] longitude:[self.sharedLong doubleValue]];
    [geoCoder reverseGeocodeLocation: currentLocation completionHandler:
     ^(NSArray *placemarks, NSError *error)
     {
     //Get nearby address
     self.placemark = [placemarks objectAtIndex:0];

     //String to hold address
     NSString *locatedAt = [[self.placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
     // NSLog(@"City = %@",placemark.locality);
     // NSLog(@"Country = %@",placemark.country);

     self.currentCity = self.placemark.locality;
     self.currentCountry = self.placemark.country;

     //Print the location to console
     NSLog(@"I am currently at %@ City",self.currentCity);
     }];
}

为什么在startUpdatingLocation之后才能获得地址?这意味着,如果找到任何位置,则必须在获得位置的委托方法之后才能获得地址。这就是导致无Zip问题的原因?或者这只是我应该解决的问题?我想这是没有获得zipcode的主要问题。有关更多详细信息,请参阅我的答案。