/ Published in: jQuery
Multiple markers function for Google Maps API V3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var map = { init: function(){ var $map = $('#map'); var config = { zoom: 9, center: new google.maps.LatLng(52.376063,0.251936), mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map"),config); switch($map.parent().attr('id')){ case 'hf': var markers = [ ["Cambridge", "Queen Anne House", "Gonville Place<br />Cambridge<br />CB1 1ND", "52.20078", "0.12938"], ["Peterborough", "The Cresset", "Rightwell<br />Bretton<br />Peterborough<br />PE3 8DX", "52.58930", "-0.28354"] ]; break; default: var markers = [ ["Cambridge", "Queen Anne House", "Gonville Place<br />Cambridge<br />CB1 1ND", "52.20078", "0.12938"], ["Peterborough", "The Cresset", "Rightwell<br />Bretton<br />Peterborough<br />PE3 8DX", "52.58930", "-0.28354"], ["Peterborough", "Haward House", "Rightwell<br />East Bretton<br />Centre Bretton<br />Peterborough<br />PE3 8DX", "52.58930", "-0.28354"], ["Peterborough", "Time Stop", "101 Wellington Street<br />Eastgate<br />Peterborough<br />PE1 5DU", "52.57414", "-0.23098"], ["Wisbech", "Wisbech", "4-6 Stermyn Street<br />Wisbech<br />Cambridgeshire<br />PE13 1EQ", "52.66388", "0.16319"] ]; } this.markers(map, markers); }, markers: function(map, markers){ var infowindow = new google.maps.InfoWindow(); for(var i=0;i<markers.length;i++) { var city = markers[i][0], name = markers[i][1], address = markers[i][2]; var latlngset = new google.maps.LatLng(markers[i][3], markers[i][4]); var marker = new google.maps.Marker({ map: map, title: name, icon: folder+'/img/contact-marker.png', position: latlngset, content: '<div class="infowindow"><strong>' + city + '</strong><p>' + name + '<br />' + address + '</p><a href="http://maps.google.com/?daddr=' + address.replace(/<br\s*[\/]?>/gi,',') + '" target="_blank">Get Directions</a></div>' }); google.maps.event.addListener(marker, 'click', function () { infowindow.setContent(this.content); infowindow.open(map, this); }); } } };