Display multiple markers in Google Map

D

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Google Map</title>
<script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”></script>
<script type=”text/javascript”>
var markers = [
[‘Bondi Beach’, -33.890542, 151.274856],
[‘Coogee Beach’, -33.923036, 151.259052],
[‘Cronulla Beach’, -34.028249, 151.157507],
[‘Manly Beach’, -33.80010128657071, 151.28747820854187],
[‘Maroubra Beach’, -33.950198, 151.259302] ];

function initializeMaps() {
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
//mapTypeId: google.maps.MapTypeId.TERRAIN
mapTypeControl: true
};
var map = new google.maps.Map(document.getElementById(“map_canvas”),myOptions);
var infowindow = new google.maps.InfoWindow();
var marker, i;
var bounds = new google.maps.LatLngBounds();

for (i = 0; i < markers.length; i++) {
var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(pos);
marker = new google.maps.Marker({
position: pos,
map: map
});
google.maps.event.addListener(marker, ‘click’, (function(marker, i) {
return function() {
infowindow.setContent(markers[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
map.fitBounds(bounds);
}
</script>

</head>

<body onLoad=”initializeMaps()” style=”text-align:center”>
<div id=”map_canvas” align=”center” style=”width: 800px; height: 500px; text-align:CENTER; left: 250px; top:10px;”></div>
</body>
</html>

About the author

swati nuna
By swati nuna

Category