I got it, basically, you have to do the actual marker creation in a
seperate function. Here is what I came up with:
function createMarker(map,myLatLng, GMarkerOptions, beach)
{
var marker = new GMarker(myLatLng, GMarkerOptions);
map.addOverlay(marker);
new GEvent.addListener(marker, "click", function() {
map.openInfoWindow(marker.getLatLng(),
document.createTextNode(beach[0]));});
}
function setMarkers(map,locations)
{
for(var i = 0; i < locations.length; i++) {
var beach = locations[i];
var icons = new GIcon(G_DEFAULT_ICON);
icons.image = "/" + beach[4];
icons.shadow = "";
var GMarkerOptions = {
icon: icons,
title: beach[0]};
var myLatLng = new GLatLng(beach[1], beach[2]);
createMarker(map,myLatLng, GMarkerOptions,beach);
}
map.addControl(hsrControl);
}
Originally, I had all of the code in createMarker where the
createMarker call is in setMarkers. Use a seperate function to create
the marker and assign a click event and viola!
Thanks for pointing me in the right direction Rossko!
On May 11, 2:52 pm, Rossko <[email protected]> wrote:
> > I have a map located here:www.weareduckhunters.com/map2.phpthat I am
> > developing for a client.
>
> No map in FF2 - "initialize is not defined".
> Can't find any maps related scripts among that lot?
>
> > I'm trying to bind an event to each marker on
> > click. I want the user to click the marker and then an infoWindow pops
> > up on the marker with some text in it. I thought I've set this up
> > right, but whenever I click on a marker, it only pops up on one
> > location, not the one actually clicked. It's like the event only gets
> > binded to the last marker in the loop.
>
> Really sounds like a variant of pitfall #3http://econym.org.uk/gmap/basic1.htm
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/google-maps-api?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.