3

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


}
Will Smith
  • 339
  • 1
  • 4
  • 13

1 Answers1

2

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.

Jonathan Wareham
  • 3,357
  • 7
  • 46
  • 82
  • ok. Thanks a lot. do you know how to set delay time betweeen request of geocode. are there any method that calls when geocode response? – Will Smith Oct 09 '12 at 08:04
  • I think maybe using an NSTimer would be good - you could use the repeat option to geocode a number at a time with a short delay between, then invalidate the NSTimer once all locations have been geocoded. There's lots of examples of NSTimer on SO. – Jonathan Wareham Oct 09 '12 at 08:43