piaChai
piaChai

Reputation: 1571

iOS reverse geocoding issue not returning value for placemark.locality

I encountered a very odd issue when I use CLGeocoder to get current city name. The place I'm using to verify this is Cupertino. I am 100% sure it's not a coverage issue.

The NSLog printed the placemark correctly, but when it came to placemark.locality, then it printed (null). I tried other properties and they all work. I look around and people seem to have similar problems, but no there are no feasible answers. Thanks in advance for your kind help.

The code is below:

[geoCoder reverseGeocodeLocation:newLocation
                       completionHandler:^(NSArray *placemarks, NSError *error) {  

                           NSLog(@"%@",placemarks);

                           CLPlacemark *placemark =[placemarks objectAtIndex:0];
                           NSLog(@"%@",placemark);
                           NSString *city = placemark.locality;
                           NSLog(@"City:%@", city);
                           if (!city){
                              city = placemark.subAdministrativeArea;
                           }
                           NSLog(@"City:%@", city); 

Upvotes: 4

Views: 798

Answers (1)

Engnyl
Engnyl

Reputation: 1380

Could you try this,

[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            for (CLPlacemark *placemark in placemarks) {
                NSString *city = [placemark locality];
                NSLog(@"%@", city);
            }
}

Upvotes: 3

Related Questions