带有Geocode的Google地图返回null

时间:2012-11-28 13:42:41

标签: javascript google-maps google-maps-api-3

我正在使用Google地图从一系列邮政编码中放置标记,但它只放置了大约10%的邮政编码。其余的返回null结果。我找不到问题。这是我的代码。

<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>

locations是一个邮政编码数组:

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 个答案:

答案 0 :(得分:2)

地理编码器受配额和费率限制。您没有检查错误情况(如果返回的状态不正确,则没有代码)。

或者:

  1. 查找超出配额的错误代码并智能处理(添加延迟并重试,只有成功添加标记)
  2. 将邮政编码离线地理编码并存储坐标,使用这些坐标显示标记。