I'm trying to create a Google Map with multiple markers on it, that loads an alert when a marker is clicked.
var map = null;
function setupMap() {
map = new GMap2(document.getElementById("map"));
map.setUIToDefault();
map.setCenter(new GLatLng( 0, 0 ), 1);
map.enableDoubleClickZoom();
// Create the marker icon - will be repeated for each icon but
// truncated for brevity in example
var icon1 = new GIcon(G_DEFAULT_ICON);
icon1.image = "uploads/1.jpg";
icon1.shadow = "";
icon1.iconSize = new GSize( 50, 50 );
var latlng = new GLatLng( 0, 0 );
markerOptions = { icon:icon1 };
marker1 = new GMarker( latlng, markerOptions );
map.addOverlay( marker1 );
GEvent.addListener( marker1, "click", loadInfo(1) );
}
function loadInfo( a ) {
alert( a );
}
window.onload = setupMap;
In the working example, I'll pass the marker object to loadInfo() and then load an InfoWindow, but for now, I'm just trying to get the action to happen when the marker is clicked. What's actually happening is that an alert box is loading (with the '1' in it, as expected) when the map loads. Multiple markers don't load multiple alert boxes, and after the initial alert box has loaded (which I don't want) clicking the markers doesn't do anything.
Any help is much appreciated, thanks!