Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need more coordinates from CLGeocoder than the limit

following code is returning me coordinates only for first 10 addresses. But i need more than 100 to store that in a database. is there a limit of geocoder? how can i do it ?

 for(int i=0;i<count;i++)
{

    CLGeocoder *geoCode = [[CLGeocoder alloc] init];

    [geoCode geocodeAddressString:strcity completionHandler:^(NSArray *placemarks, NSError *error)
     {
         if (!error)
         {
             CLPlacemark *place = [placemarks objectAtIndex:0];
             CLLocation *location = place.location;
             CLLocationCoordinate2D coord = location.coordinate;

             NSString *tempLati=[[NSString alloc]initWithFormat:@"%g",coord.latitude];
             NSString *tempLongi=[[NSString alloc]initWithFormat:@"%g",coord.longitude];




             [objCountries.countryLatitude addObject:tempLati];
             [objCountries.countryLongitude addObject:tempLongi];

             [geoCode cancelGeocode];
         }
     }];


}
like image 609
Will Smith Avatar asked Oct 24 '25 08:10

Will Smith


2 Answers

iOS throttles CLGeocoder requests, it varies but generally allows 50 or so requests at a time. The time period is an unknown. What you can do is code it to geocode a chunk at a time, leaving an adequate pause in between. Wherever possible once read you should store the result so you don't request the same geocode again. Take note of the CLGeocoder documentation here : CLGeocoder . Apple can restrict you or even suspend your developer account if the gecoding services are abused.

like image 97
Jonathan Wareham Avatar answered Oct 26 '25 23:10

Jonathan Wareham


Making 35 requests at a time, pausing until they complete, and then making another 35 works consistently.

You need to wait 90 seconds between cycles.

In my experience with one app, this approach has reliably avoided rate limits for about a year and a half (April 2023 - October 2024).

like image 21
spnkr Avatar answered Oct 27 '25 00:10

spnkr