> Hi Rossko - thanks for chiming in. Getting at the XML data hasn't been
> a problem, because I've been able to create markers from it (if that'
> what you mean, I'm not 100% sure by the link you sent).

Mike's basic3 example reads XML and has different infowindows for each
marker ; it works because it gets function closure.  It's an example
of how the magic works.

> So, yes, my
> GMarker creation and listener adding code is already in the same
> function as the one as one which draws from the XML source:

Ok, so that means it doesn't get function closure .... it's pitfall
#3, only one copy of 'marker', etc.

> I tried to alter my code, changing var marker = new GMarker(latlng,
> markerOptions); to this:
>         var marker = createMarker(latlng);

That's good, calling a function from a function (createMarker() from
retrieveMarkers()) will allow you to get closure within the listeners
you set up in the inner function - a snapshot, if you like, of the
state of 'marker' etc. when the listeners were created.

The only problem is that you don't seem to have written any
createMarker() function.

> I'm not
> really sure that moving everything to a separate function when all the
> variables are already declared in the first function is really going
> to help.

That's the magic of function closure, did say it wasn't easy to grasp,
it isn't intuitive at all.

> Would declaring the variable 'marker' outside of the function
> help?

Nope.  It carries the danger of destroying the effect ; if your inner
function uses a variable 'marker' that has been declared in global
scope, you are back to having only one 'marker' again.

-- 
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.

Reply via email to