簡體   English   中英

帶有地理編碼的 Google 地圖返回 null

[英]Google Maps with Geocode returning null

我正在使用 Google 地圖從一組郵政編碼中放置標記,但它只放置了大約 10% 的標記。 其余的返回空結果。 我找不到問題。 這是我的代碼。

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language=en"></script>
<script type="text/javascript">     
  var latlng = new google.maps.LatLng(37.09024, -95.712891);
  var map = new google.maps.Map(document.getElementById('pledge-map'), {
    zoom: 4,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });               
  var geocoder = new google.maps.Geocoder();
  var locations = <?php echo(json_encode($zips)); ?>        
  for (var i = 0; i < locations.length; i++) {                
    geocoder.geocode( { 'address': locations[i]}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        var marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
          });
      }
    });     
  }
</script>

location 是一組郵政編碼:

locations =["20190","22192","20148","06078","95136","84120","53066","53404","48323","52404","72762","89701","39667","78073","78016","76013","15613","84010","77662","77407","30127","94566","14625","45629","27406","27289","02339","01864","39116","77079","10954","37683","72801","19341","14580","64133","29579","08527","32258","33433","60093","76691","78261","77095","19426","10469","92038","85208","67220","61031","85706","72223","21222","66224","34242","30224","56232","32746","08558","72712","14209","43015","52722","32779","33518","33578","60565","11239","17007","60623","77469","20165","20002","36116","20769","20815","34209","02301","60025","48158","38804","30736","01803","45040","48069","07463","53018","73008","80951","70785","72065","91510","91506","67209","22408","36849"]   

地理編碼器受配額和速率限制的約束。 您沒有檢查錯誤情況(如果返回的狀態不正確,則沒有代碼)。

任何一個:

  1. 查找配額超出錯誤碼並智能處理(加延時重試,成功才加marker)
  2. 離線對郵政編碼進行地理編碼並存儲坐標,使用這些來顯示您的標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM