谷歌地图信息窗口问题?

时间:2011-01-03 06:42:59

标签: google-maps-api-3

这段代码有什么问题。我刚开始学习google maps api..im无法获取信息窗口。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 1,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    var lat=new Array("-31.203405");
    var lon=new Array("125.244141");
    var msg = ["brisbane","japan","delhi","abc","xyz"];

        for (var i=0;i<10 ;i++ )
        {
         var msg = ["This","is","the","secret","message"];
        var location=new google.maps.LatLng(lat[i],lon[i]);
            var marker = new google.maps.Marker({
            position:location,
            map:map
            });
        marker.setTitle("bobby");
            var infowindow = new google.maps.InfoWindow({
            content:msg[i],
            size : new google.maps.Size(50,50)
            });
            google.maps.event.addListener(marker,'click', function() {
            infowindow.open(map,marker);
            });
        }
  }

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

你的lat和lon数组只有一个元素,但你试图访问0到9的元素。你的msg数组也存在类似的问题。

尝试更改:

var i = 0; i < 10; ++i

var i = 0; i < 1; ++i 

看看它是否有效。