Google Map Infowindow Closure?
as part of my last.fm/google maps event mashup, I have to plot markers dynamically from last.fm API onto the google map. This is all well but when I click the marker, only the last
Solution 1:
An easy way to isolate the scope of your marker
variable is to wrap the invocation in an anonymous function:
var map = ...
(function() {
var image = ...
var marker = ...
...
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
})();
As described here, the anonymous function will see anything in scope where it was declared. So inside the function can see map
, which was in scope when it was declared. But outside the function, marker
is invisible, so repeated clones of the anonymous function won't impact each other.
Post a Comment for "Google Map Infowindow Closure?"