How can I put multiple markers on Google maps with Javascript API v3?

Posted by Doe on Stack Overflow See other posts from Stack Overflow or by Doe
Published on 2010-04-03T23:06:46Z Indexed on 2010/04/03 23:13 UTC
Read the original article Hit count: 672

Filed under:

Hi, I'd like to know how to put multiple markers for Google Maps using Javascript API v3.

I tried the solution posted here:

but it does not work for me for some reason.

var directionDisplay;

  function initialize() {

var myOptions = { zoom: 9, center: new google.maps.LatLng(40.81940575,-73.95647955), mapTypeId: google.maps.MapTypeId.TERRAIN }
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
setMarkers(map, properties);

var properties = [
['106 Ft Washington Avenue',40.8388485,-73.9436015,'Mjg4'],

function setMarkers(map, buildings) {
    var image = new google.maps.MarkerImage('map_marker.png', new google.maps.Size(19,32), new google.maps.Point(0,0), new google.maps.Point(10,32));
    var shadow = new google.maps.MarkerImage('map_marker_shadow.png', new google.maps.Size(28,32), new google.maps.Point(0,0), new google.maps.Point(10,32));
    var bounds = new google.maps.LatLngBounds;
    for (var i in buildings) {
        var myLatLng = new google.maps.LatLng(buildings[i][1], buildings[i][2]);
        var marker = new google.maps.Marker({ position: myLatLng, map: map, shadow: shadow, icon: image, title: buildings[i][0] });
        google.maps.event.addListener(marker, 'click', function() { window.location = ('detail?b=' + buildings[i][3]); });


Could anyone kindly explain why this doesn't work for me?

© Stack Overflow or respective owner

Related posts about google-maps