A very similar discussion (having to do with Closures) is going on right now here: http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/d1a079cf914a7e07
As I said in that thread, Closures are hard to understand, but not that hard to do. Personally, I think the way that http://econym.org.uk/gmap/basic1.htm structures the code makes the whole thing seem even more magical than it already is. (But he's been around a lot longer than I have, so pick who you listen to.) The problem in your code is that when the click event fires, your anonymous function will try to evaluate map, marker at that time. map is okay (it didn't change), but marker isn't even the right type (it's an array of markers, not a marker). If marker were the right type, it would evaluate at the time of the click event (NOT at the time the listener was attached), and just give you the last marker for every click. What a closure does for you is set the scope of your anonymous function to another function that has already returned (and but-for closure would be completely gone). So the variables in the scope have the values they had when the listener is attached. Good luck! On Jan 17, 3:51 pm, "[email protected]" <[email protected]> wrote: > On Jan 17, 2:37 pm, Rossko <[email protected]> wrote: > > > > I agree with you...but I can't make it work...help me ;) > > > Structure your code the way thathttp://econym.org.uk/gmap/basic1.htm > > Here is my quick and dirty port of that map to > v3:http://www.geocodezip.com/v3_MW_example_map1.html > > -- Larry > > > > > > > > > is structured. > > The important part is putting your marker creation and listener adding > > into a seperate function, so that it can get closure when it is called > > from inside the loop. > > Here's a v3 > > examplehttp://code.google.com/apis/maps/documentation/javascript/examples/ev... -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" 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-js-api-v3?hl=en.
