最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 620: Too many queries using Google Maps API - Stack Overflow

programmeradmin1浏览0评论

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 pleted given that they're asynchronous?

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

function replaceAddresses() {
    var delay = 0;
    $(".lat-lon-address").each(function(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;
    }
}

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 pleted given that they're asynchronous?

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

function replaceAddresses() {
    var delay = 0;
    $(".lat-lon-address").each(function(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;
    }
}
Share edited Oct 11, 2010 at 17:40 yayitswei asked Oct 11, 2010 at 17:15 yayitsweiyayitswei 4,6875 gold badges29 silver badges34 bronze badges 5
  • 5 code.google./apis/maps/documentation/geocoding/#Limits – pharalia Commented Oct 11, 2010 at 17:19
  • 1 Not sure if its applicable, but I remend caching the results so you don't have to hit Google so often – Jarrett Widman Commented Oct 11, 2010 at 17:19
  • 2 @jarrett: Caching is not that practical with reverse geocoding. It's much more feasible with normal geocoding (address to coordinates). – Daniel Vassallo Commented Oct 11, 2010 at 17:23
  • I'd suggest showing the code for queryGeocoder() so we can see what you do for success vs. failure, otherwise I don't think you're going to be able to get the help you need. – Matt Huggins Commented Oct 11, 2010 at 17:37
  • originally I thought it would plicate the post unnecessarily, but I think you're right-- added. – yayitswei Commented Oct 11, 2010 at 17:41
Add a ment  | 

2 Answers 2

Reset to default 2

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 ply with the terms of service? I don't see any code that displays these results on a map (as per ToS).

发布评论

评论列表(0)

  1. 暂无评论