Created
April 25, 2011 21:33
-
-
Save michaelhelmick/941285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var markersArray = []; | |
// For sake of simplicity, I'm assuming you're using jQuery | |
// data variable that contains latitudes and longitudes of positions | |
for(var i=0; i<data.length; i++){ | |
var glatLng = new google.maps.LatLng(data[i].latitude, data[i].longitude); | |
var marker = new google.maps.Marker({map: map, position: glatLng}); | |
markersArray.push(marker); | |
var $p = $('<p />'); | |
// set a data attribute with the id of the marker in your markersArray variable | |
var $a = $('<a />').attr({'href':'#', 'class':'forceMarkerClick'}).data('markerId':(markersArray.length-1)).text('Click this marker!'); | |
// This will put a link in the body for you to click for each marker. | |
$('body').append($p.append($a)); | |
} | |
$('.forceMarkerClick').live('click', function(e){ | |
e.preventDefault(); | |
google.maps.event.trigger(markersArray[$(this).data('markerId')], 'click'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment