Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More batch geocoding questions with the Google Maps API v3

I'm trying to figure out a nice way to limit the rate at which I send geocode requests to the Google Maps API v3 geocoder service. I know that Javascript does not have any nice wait or sleep because its execution is, for the time being, single-threaded.

Each geocoder request is sent inside of a jQuery each function. So, the general code skeleton is:

$(xml).find('foo').each(function(){
    // do stuff
    ...

    geocoder.geocode(request, function(results, status) {/* do other stuff */});

    // do more stuff
    ...
}

How can I set a fixed interval to wait in between each call to geocode? If I send each request as fast as Javascript will run, then I quickly start receiving OVER_QUERY_LIMIT responses - even if I'm only sending 20 requests. This is expected, and I'm trying to make my client play nicely with Google's service.


An alternate route I'm willing to pursue is to completely abandon Javascript for geocoding, and write it all in Java. With Java it would be really easy to sleep in between requests.

However, I couldn't find a way to use Google's geocoding service (specifically, using version 3 of the API) in Java. GeoGoogle seems to be more than a year out of date, and uses v2.

Can it be done in Java, and if so, how?

like image 658
Matt Ball Avatar asked Jan 23 '23 04:01

Matt Ball


1 Answers

Google is actively developing v2 and v3 of the Maps API separately. v3 is a much slimmer version suitable for devices with limited processing power or basic mapping tasks (and doesn't need an API key to work).

In either case, if you're geocoding many things you should probably look at using Google's HTTP geocoding service (http://code.google.com/apis/maps/documentation/geocoding/index.html). This will avoid the rate limiting issue.

And fwiw: Javascript can do basic sleep/wait operations using setInterval() and setTimeout(). Just fire the request and reset the timer to do it again at the end of your callback processing.

like image 79
Ty W Avatar answered Feb 19 '23 22:02

Ty W