function multi_marker() { var map = new google.maps.Map(document.getElementById("map"), { zoom: 5, center: new google.maps.LatLng(22.7964,79.5410), mapTypeId: google.maps.MapTypeId.ROADMAP }); var markers = [ { position: new google.maps.LatLng(25.1652,75.7617), map: map, title: 'Kota' }, { position: new google.maps.LatLng(22.7154,75.7617), map: map, title: 'Indore' }]; for (id=0; id<markers.length; id++) { new google.maps.Marker(markers[id]); } }
<html> <head> <title> Google Maps API v3 - Multiple markers using array </title> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> <!-- Copy the Javascript here if you trying out this code. --> </script> </head> <body onload="multi_marker()"> <div id ="map" style="width: 550px; height: 250px"> </div> </body> </html>