用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2798|回复: 2
收起左侧

一个 google JS API的问题

[复制链接]
发表于 2012-4-17 11:11:29 | 显示全部楼层 |阅读模式
本帖最后由 zionwang 于 2012-4-18 17:18 编辑

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


HTML复制代码
 
<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[0] = "厦门"
        arr_new[1] = "泉州"
        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[i]
           });
           geocoder.geocode({
               'address': arr_new[i]
           }, 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
                   });
                   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>
 
 
 
复制代码

 楼主| 发表于 2012-4-18 11:17:32 | 显示全部楼层
有木有人
 楼主| 发表于 2012-4-19 10:59:52 | 显示全部楼层
没有人解答吗

本版积分规则