Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Created April 25, 2011 21:33
Show Gist options
  • Save michaelhelmick/941285 to your computer and use it in GitHub Desktop.
Save michaelhelmick/941285 to your computer and use it in GitHub Desktop.
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