javascript - Google Maps API v3 - why no context with events? -


The first time Google Maps is using API v3 and I got a map with a group of markers. I wanted to make it because when you click on one, a specific info window will appear (specific for the marker you click on). I was really surprised that click event does not tell you the actual marker clicked!

I know that there is a solution using a different method for creating closures, but it seems like I have a better way to do it? Or, is there a way to ask the map, "which markers are present in this situation" and the incident passes through reasoning?

I hope events to work in this way:

  google.maps.event.addListener (marker, 'click', function (event, obje) {// Now I can work with "obj" - what was clicked on.});    

You should mention 'this' in the event listener.

  google.maps.event.addListener (marker, 'click', function (e) {// it == marker; // e == mouse event});    

Comments