开发者

620: Too many queries using Google Maps API

I'm using the Google Maps Javascript API V3 to reverse-geocode a lot of locations (~100) on a page. After about 10 or so, I start getting a 620 error: too many queries.

What's a good way to delay the requests and ensure that they all get completed given that they're asynchronous?

EDIT: Here's what I have so far. It completes all the requests most of the time, but it doesn't retry failed requests.

function replaceAddresses() {
    var delay = 0;
    $(".lat-lon-address").each(f开发者_StackOverflow社区unction(index) {
        window.setTimeout(queryGeocoder, delay, this);          
        delay += 1000;
    });
}

function queryGeocoder(elem) {
    geocoder.getLocations(new GLatLng(
        elem.getAttribute("lat"),
       elem.getAttribute("lon")), 
        function(response) {
            handleAddress(response, elem);
        }); 
}

function handleAddress(response, elem) {
    if (!response || response.Status.code != 200) {
        console.log("status code: " + response.Status.code)
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);

        elem.innerHTML = place.address;
    }
}


Last time I checked you are only allowed 2500 geocoding requests per day (based on your ip). This should be enough for you but you may need to purchase a larger limit if you use larger data sets.

Tips

Store your geocoded information locally, perhaps in a database. Fetch the values from the database instead of using Google's web service. It'll be much faster this way also. If a location is missing geographical information only then should you geocode it.

When you write some new code which uses geocoding don't test it with all 600 addresses, first try one or 2 addresses to make sure you don't needlessly blow through half your daily allowance with some dysfunctional code.

Do the geocoding client side if you can, this won't count towards your limit.


If you're getting 620, you probably need to throttle or reduce the number of requests.

Does your implementation comply with the terms of service? I don't see any code that displays these results on a map (as per ToS).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜