reverseGeocodeLocation not working every time

2.5k views Asked by At

I am facing some weird issue with reverseGeocodeLocation. This is what I do.

I push from one view controller to another. After view appears, I calls for current location. In didUpdateLocations delegate when I receives current location, I call for reverseGeocodeLocation to get the place mark values.

Problem

  1. At times it works like charm
  2. At times it waits and shows the result after long time interval
  3. At times I don't get any result.

Below is my code to get reverse geo location

- (void)getReverseLocation
{
 __block CLPlacemark* placemark;

    CLGeocoder* geocoder = [CLGeocoder new];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
     {
         if(error)
             NSLog(@">>>>>>>> Error in reverseGeoLocation - %@", [error localizedDescription]);

         if (error == nil && [placemarks count] > 0)
         {
             placemark = [placemarks lastObject];

             completionBlock(placemark);
         }
     }];
}

I am not sure why its behaving like this. I am at same location and internet connectivity is good.

Is this because of threads? I have tried this on main thread too. But same problem.

Edit : I got this error, After some tries

Error in reverseGeoCodeLocation - The operation couldn’t be completed. (kCLErrorDomain error 8.)

1

There are 1 answers

0
justColbs On BEST ANSWER

Here is why you get results sometimes, others not. Straight from Apple's Docs on Geocoding

Applications should be conscious of how they use geocoding. Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. (When the maximum rate is exceeded, the geocoder returns an error object with the value kCLErrorNetwork to the associated completion handler.)