I'm using the below code but i'm little confuse with click event. How, can i add click event on every marker??
var address = 'Dubai'; var neighborhoods = [ new google.maps.LatLng(25.23247465817403, 55.30191340351564), new google.maps.LatLng(25.244586082480332, 55.29822268391115), new google.maps.LatLng(25.230844181976337, 55.32225527668459), new google.maps.LatLng(25.224787936110832, 55.28526224995119) ]; var markers = []; var iterator = 0; var map; var geocoder = new google.maps.Geocoder(); function initialize() { var mapOptions = { zoom: 12, }; map = new google.maps.Map(document.getElementById('mapCanvas'), mapOptions); geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); } }); } function drop() { for (var i = 0; i < neighborhoods.length; i++) { setTimeout(function () { addMarker(); }, i * 200); } } function addMarker() { var image = 'img/flagred.png'; markers.push(new google.maps.Marker({ position: neighborhoods[iterator], map: map, icon: image, title:"Hello World!", draggable: false, animation: google.maps.Animation.DROP })); iterator++; }
I have looked at the other answers here but that didnt solve my problem.