Hm, in my oppinion it's not clear what he means by "unroll" in that
pitfall.

The reason is closures. JS has no block scope and any variable created
inside a for loop will be remembered. Redefining the variable actually
simply uses the previous variable. So when you create the anonymous
functions the container (not the value) is remembered and shared
accross all anonymous functions created this way. Because the
container is remembered, but changed by the loop, the last value of
the variable is remembered and used by all anonymous functions.

On 9 feb, 23:40, "[email protected]" <[email protected]> wrote:
> On Feb 9, 2:12 pm, andi-hro <[email protected]> wrote:
>
>
>
> >  all my markers are shown from the loop and every marker gets a
> > listener, but only the last marker in the loop shows the infowindow. 
> > -->click on the first or second marker only shows the infowindow from
>
> > last marker on the position of the last marker.
>
> > for.........{
> > ......................
> >          var marker = new GMarker(latlng);
> >          map.addOverlay(marker);
> >          GEvent.addListener(marker, "click", function(overlay, latlng2)
> > {
> >             marker.openInfoWindow (nodex.node.name);
> >          });
>
> > }
>
> > all values (latlng or nodex.node.name) are different.
>
> > i wanted to have a infowindow on every marker?!?
>
> Please review the posting guidelines (and provide a link to your map
> that shows the 
> problem):http://groups.google.com/group/Google-Maps-API/web/suggested-posting-...
>
> For working examples see Mike Williams' tutorial:http://econym.org.uk/gmap/
>
> Pay particular attention to Pitfall #3 on this 
> page:http://econym.org.uk/gmap/basic1.htm
>
>   -- Larry- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
--~--~---------~--~----~------------~-------~--~----~
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