simplyblue
simplyblue

Reputation: 2347

Google maps info window problem?

Is there anything wrong with this code.I just started learning google maps api..im unable get the info window.

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

Upvotes: 0

Views: 858

Answers (1)

plexer
plexer

Reputation: 4622

Your lat and lon arrays have only one element, but you attempt to access elements 0 through 9. A similar problem exists for your msg array.

Try changing:

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

to

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

and see if it works.

Upvotes: 1

Related Questions