0

I'd like to ask for a second opinion for my solution in reverse Geocoding in getting a user's current location:

 - (void)reverseGeocodeLocation:(CLLocation *)location
{ 
    CLGeocoder* reverseGeocoder = [[CLGeocoder alloc] init];
    if (reverseGeocoder) {
        [reverseGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
            CLPlacemark* placemark = [placemarks firstObject];
            if (placemark && [placemark count] > 0) {
                 //Using blocks, get zip code
                 NSString *zipCode = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
            }
        }];
    }
    else{
        MKReverseGeocoder* revGeo = [[MKReverseGeocoder alloc] initWithCoordinate:location.coordinate];
        revGeo.delegate = self;//using delegate
        [revGeo start];
        [revGeo release]; 
    }
    [reverseGeocoder release];
}

however, there seemed to be a bit of a problem...I encountered an EXC_BAD_ACCESS error pointing at:

[reverseGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
            CLPlacemark* placemark = ...
        }];

Could you please tell me what went wrong? I received an EXC_BAD_ACCESS error.

1 Answer 1

1

You're not checking the error sent to the block. You're presuming that you get at least one placemark returned, but the array may be empty for some reason. That certainly could be the source of your EXC_BAD_ACCESS error.

1
  • I was able to find a solution for this. Thanks for your tip!
    – Kimpoy
    Commented Jun 4, 2012 at 23:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.