Will Smith
Will Smith

Reputation: 349

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];
         }
     }];


}

Upvotes: 4

Views: 2659

Answers (2)

spnkr
spnkr

Reputation: 1362

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).

Upvotes: 1

Jonathan Wareham
Jonathan Wareham

Reputation: 3397

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.

Upvotes: 2

Related Questions