OVER_QUERY_LIMIT in Google Maps API v3: How do I pause/delay in Javascript to slow it down?

前端 未结 6 1932
暖寄归人
暖寄归人 2020-11-22 08:49

I\'m hitting an issue that is WELL discussed in these forums, but none of the recommendations seem to be working for me so I\'m looking for some full javascript that works w

6条回答
  •  忘了有多久
    2020-11-22 09:32

    Nothing like these two lines appears in Mike Williams' tutorial:

        wait = true;
        setTimeout("wait = true", 2000);
    

    Here's a Version 3 port:

    http://acleach.me.uk/gmaps/v3/plotaddresses.htm

    The relevant bit of code is

      // ====== Geocoding ======
      function getAddress(search, next) {
        geo.geocode({address:search}, function (results,status)
          { 
            // If that was successful
            if (status == google.maps.GeocoderStatus.OK) {
              // Lets assume that the first marker is the one we want
              var p = results[0].geometry.location;
              var lat=p.lat();
              var lng=p.lng();
              // Output the data
                var msg = 'address="' + search + '" lat=' +lat+ ' lng=' +lng+ '(delay='+delay+'ms)
    '; document.getElementById("messages").innerHTML += msg; // Create a marker createMarker(search,lat,lng); } // ====== Decode the error status ====== else { // === if we were sending the requests to fast, try this one again and increase the delay if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) { nextAddress--; delay++; } else { var reason="Code "+status; var msg = 'address="' + search + '" error=' +reason+ '(delay='+delay+'ms)
    '; document.getElementById("messages").innerHTML += msg; } } next(); } ); }

提交回复
热议问题