Today I've tried to place markers with a label at the Google Maps Api. Each marker gets a eventListener. Now if a marker is clicked, the last marker reacts but not the one who's clicked. Can anybody help me?

Now if a marker is clicked, the last marker reacts but not the one who's clicked.

The old closure problem eh?

An explanation:

You're creating your markers in a loop using i as a variable that is supposed to reference the current marker...however, in the scope that you are dealing with, i keeps incrementing until the end of the loop at which point it is equal to the index of the marker index that you created last. Therefore, when you event listener is run (by clicking on a marker) the function that is executed says 'now, I have an i variable in here and it wasn't declared from within me, so what was the value of i in the scope where I was created?' and it goes and gets it, which, at that point, is not the same i as when it was created.

What you need to do, is create a closure - create a new scope where the variable retains its value like this:

Code:

for (i = 0; i < winkels.length; i++) {

//...the code to create your marker....

//a closure which assigns the current value of i to a variable called num within a new scope
(function(num) {