On Jul 13, 9:01 am, redvibes <[email protected]> wrote:

> The core of the problem is the "buff" variable. It is supposed to
> assign the identifier "coords[i][3]" to the URL but instead of
> iterating, it always assigns the same value "42", form the last row of
> coords. What is wrong with this loop? I know that this could only be
> my programming error but I thought it would be easier to explain the
> problem to you geocoders rather than js programmists.

Pitfall Number 3. http://econym.org.uk/gmap/basic1.htm

You should use a helper function to create your markers and set up
listeners and things. "buff" is in global scope; when the listener is
triggered, the function is run and "buff" is evaluated so that "url"
can be assigned. At that point, "buff" will have been set by the last
iteration of the loop. Using a helper function creates a closure which
"binds" the correct value of buff to the event listener. One way of
doing this with minimal damage to your existing code is below; BUT you
could probably do better by using a helper function to create your
markers as Mike demonstrates in his example which I linked to.

var buff = coords[i][3];
createListener(marker,buff);

function createListener(thisMarker,urlValue) {
  GEvent.addListener(thisMarker,"click",function() {
    url = "index_pl.php?s=wyprawa&img=" + urlValue;
    window.location = url;
    });
  }

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