zionwang 发表于 2012-4-17 11:11:29

一个 google JS API的问题

本帖最后由 zionwang 于 2012-4-18 17:18 编辑

google地图API打不开啊 js v3 版本的, 如何用地址查询到点啊,这样的循环显示,为什么有点问题, 每第一次打开都错误, 然后坐标提示只能提示最后一个?
是不是哪里循环错了?



<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
    function initialize(){
      var arr_new = new Array()
      arr_new = "厦门"
      arr_new = "泉州"
      var myOptions = {
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      geocoder = new google.maps.Geocoder();
      for (var i = 0; i < 2; i++) {
            var infowindow = new google.maps.InfoWindow({
                content: arr_new
            });
            geocoder.geocode({
                'address': arr_new
            }, function(results, status){
                if (status == google.maps.GeocoderStatus.OK) {
                  map.setCenter(results.geometry.location);
                  var marker = new google.maps.Marker({
                        map: map,
                        position: results.geometry.location
                  });
                  google.maps.event.addListener(marker, 'mouseover', function(){
                        infowindow.open(map, marker);
                  });
                  google.maps.event.addListener(marker, 'mouseout', function(){
                        infowindow.close();
                  });
                }
                else {
                  alert("Geocode was not successful for the following reason: " +
                  status);
                }
            });
      }
    }
</script>
<body style="margin: 0; padding: 0;">
<div id="map_canvas" style="width: 708px; height: 410px">
</div>
</body>



zionwang 发表于 2012-4-18 11:17:32

有木有人

zionwang 发表于 2012-4-19 10:59:52

没有人解答吗
页: [1]
查看完整版本: 一个 google JS API的问题