程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度??

开发过程中遇到Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?的问题如何解决?下面主要结合日常开发的经验,给出你关于Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?的解决方法建议,希望对你解决Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?有所启发或帮助; @H_674_2@迈克·威廉姆斯的教程中没有出现这两行:

    wait = true;
    setTimeout("wait = true", 2000);
@H_674_2@这是第3版端口:

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

@H_674_2@相关的代码位是

  // ====== 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)<br>';
            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)<br>';
            document.getElementByID("messages").INNERHTML += msg;
          }   
        }
        next();
      }
    );
  }

解决方法

@H_674_2@我遇到的问题在这些论坛上都进行了很好的讨论,但是这些建议似乎都不对我有用,因此我正在寻找一些保存为html文件时可以使用的完整javascript。

@H_674_2@问题是,当尝试使用Javascript调用的V3 API对Google
Map上的11个以上的位置进行地理编码时,我一直遇到OVER_QUERY_LIMIT错误。我了解您可以致电地理编码器的速率受到限制(以及每日总体积限制),因此我需要在数组中每个结果之间引入一个暂停。

@H_674_2@任何帮助非常感谢。

@H_674_2@这是我的代码:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var wait = false;


  function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(51.32,0.5);



var myOptions = {
  zoom: 8,center: latlng,mapTypEID: google.maps.MapTypEID.roaDMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
codeAddress('KT16 8LA' + ',UK');
codeAddress('LS8 2LQ' + ',UK');
codeAddress('NE13 8AF' + ',UK');
codeAddress('KT12 2BE' + ',UK');
codeAddress('W1W 8AN' + ',UK');
codeAddress('EC3N 2LS' + ',UK');
codeAddress('BS9 3BH' + ',UK');
codeAddress('KA10 6LZ' + ',UK');
codeAddress('EC1V 9BW' + ',UK');
codeAddress('WD18 8YN' + ',UK');
codeAddress('HA3 6DQ' + ',UK');
codeAddress('W1U 3PL' + ',UK');
codeAddress('W1T 7QL' + ',UK');
codeAddress('W1S 1TD' + ',UK');
codeAddress('SW1X 8NX' + ',UK');
codeAddress('LE2 8ET' + ',UK');
codeAddress('BA3 4BH' + ',UK');
codeAddress('AL3 8JP' + ',UK');
codeAddress('DE55 4QJ' + ',UK');
codeAddress('W6 0QT' + ',UK');
codeAddress('LA1 1PP' + ',UK');
codeAddress('SW16 4DH' + ',UK');
codeAddress('WC2N 6DF' + ',UK');
codeAddress('RM6 6LS' + ',UK');
codeAddress('S25 3QZ' + ',UK');
codeAddress('WC2H 7LR' + ',UK');
codeAddress('BH24 1DW' + ',UK');
codeAddress('EC2N 6AR' + ',UK');
codeAddress('W1U 2FA' + ',UK');
codeAddress('B60 3DX' + ',UK');    
}

  function codeAddress(vPostCodE) {
if (geocoder) {
  geocoder.geocode( { 'address': "'" + vPostCode + "'"},function(results,status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.LOCATIOn);
      var marker = new google.maps.Marker({
          map: map,position: results[0].geometry.LOCATIOn
      });
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}
}

</script>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:90%"></div>
</body>
@H_674_2@编辑:这是我试图使它在相关部分中暂停/等待的方式,但是它没有做任何事情:

function codeAddress(vPostCodE) {
    if (geocoder) {
    while (wait) { /* Just wait. */ };
      geocoder.geocode( { 'address': "'" + vPostCode + "'"},status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.LOCATIOn);
          var marker = new google.maps.Marker({
              map: map,position: results[0].geometry.LOCATIOn
          });
        /* When geocoding "fails",see if it was because of over quota error: */
        } else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) { 
        wait = true;
        setTimeout("wait = true",2000);
        //alert("OQL: " + status);
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
  }

大佬总结

以上是大佬教程为你收集整理的Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?全部内容,希望文章能够帮你解决Google Maps API v3中的OVER_QUERY_LIMIT:如何在Javascript中暂停/延迟以降低速度?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。