Google Maps - Adding multiple markers with Event Listener

Robinson

New Member
I have looked through several threads and tried various examples.. but falling short on what I need to achieve.Within the Google maps API I can position multiple markers with the relative (unique) titles / lat / long etc. What I am having trouble with is providing a unique Event Listener for each one.Each marker has some title attached to it - and all I want to do is take that data and populate a box. Currently the data populates the box - but the info is the same for whatever marker I click, rather than unique data for each marker.My code is as follows...My function to set the markers (note the event listener at the end.\[code\]function setMarkers(map, locations) {for (var i = 0; i < locations.length; i++) { var gig = locations; var myLatLng = new google.maps.LatLng(gig[1], gig[2]); var marker = new google.maps.Marker({ position: myLatLng, map: map, icon: image, title: gig[0], zIndex: gig[3], }); google.maps.event.addListener(marker, 'click', function() { $("h4#locate_me").html(gig[0]); }); } }\[/code\]On page load I call: \[code\]setMarkers(map, gigs);\[/code\] which sets up all the markers with the tooltips as the title - which is correct. \[code\]h4#locate_me\[/code\] is simply my space to populate the data when the marker is clicked.Hopefully this makes sense. Thanks in advance.
 
Top