Question

I have read that iOS limits an app to about 50 geocode requests at a time. What if I have large sets, maybe 200? Is there any way I can geocode more than 50 sets at a time? For example, using delays between sets, with each set limited to 50. What would be an ideal way to delay the geocoding between sets?

I have seen NSProgrammer's answer to the following question:

iPhone iOS5 CLGeocoder how to geocode a large (200) set of addresses?

Any suggestions for the kind of delay he mentioned? Would that delay be inside the handler and running on another thread?

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

[call geoCoderMethod];
}


-geoCoderMethod{
    [geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {

    getCo-ordinates;
    add annotation to mapview;
}

I tried splitting the array into chunks of 25 items each and calling the geoCoderMethod and induce the delay using performSelector method. But the performSelector method and geoCoder seems to be running in different threads and I am not able to cause a delay in between the method call.

Was it helpful?

Solution 2

I have a collection of addresses, and I needed to convert them into co-ordinates. What I did was to divide the collection into chunks of maximum 40 contacts(you may go up to 50, but not beyond that in a minute). So a group with over 40 contacts had to have a delay in between so that all the addresses would be processed and converted into co-ordinates before the mapview loads.

I need to load the mapview based on user requirements. In my case, the mapview could be loaded again and gain, irrespective of the contacts list in the group and irrespective of the time factor. If the user intends to load the mapview and reload it again under 1 minute I needed to develop a logic for that. For that I decided to save the state of the mapview, if the user decided to reload the same group of addresses under 1 minute.

But if the user decided to load another group of contacts, then I had to rethink my logic, based on the group of contacts to be loaded. So I had to keep track of which group was to be loaded(previous one or a new one), whether the group had number of contacts over 40 or not.

Another important factor I had to take care of was the time. For that, I had a static NSDate variable which always kept track of the "time" when the CLGeocoder worked the last time, and if the current time(when the CLGeocoder is about to use) has not got a difference of 1 minute, then I had to delay loading the map.

This is what I have done to implement mapView using co-ordinates from CLGeocoder. I am sure the logic can be optimized to a great extent and output would be faster. Would appreciate if someone comes up with a better implementation.

OTHER TIPS

Here complete solution depends on your logic. You can use a mutable array to store all your 200 addresses and run a "for loop" to limit the sending request less than 50, like 20 or 30 depends on your array count of address array. And divide with your limit to decide how many times this "for loop" should loop if you have 200 address then if you divide with 20 so that total 10 times your "for loop" will run and each run it will send 20 addresses for geocoding. So that it will not reach to 50 and easily you can retrieve.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top