Search code examples
iosmkmapviewclgeocoder

CLGeocoder only returns first look up result


I'm experiencing a weird issue with - (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;.

I have a list of locations need to be looked up. So I did something like

for (Trip *trip in takenTrips) {
    [geoCoder geocodeAddressString:trip.location completionHandler:^(NSArray *placemarks, NSError *error) {
        //handling result
    }];
}

But it seems the completion handler is only being called once. I tried making these lookups sequentially. Then everything works fine.

I searched around for a while, but couldn't find anything similar to this. I'm totally baffled here...

Any suggestion is welcomed!


Solution

  • Applications should be conscious of how they use geocoding. rules of thumb for using this class effectively: Send at most one geocoding request for any one user action. class link

    To solve your problem you could the one of the following:

    1. Do-while loop that checks if geocoder is processing geocoding
    2. NSOperationQueue to excucute one at time if it complete
    3. in the completeHandle execute a callback that run the next geocode