Google Maps API v3 - click event not firing when marker is clicked while another InfoWindow is open
I've got a setup in which multiple markers present, each loading in content to a single InfoWindow when it's clicked.
Unfortunately, it seems that the marker's click event is not being fired when it's clicked while another window is open.
This seems like an odd behavior. Has anyone else found this to be the case?
Thanks
My code below:
var infoWindow = new google.maps.InfoWindow();
if(markers) {
var length = markers.length;
for(var i = 0; i < length; i++) {
var details = markers[i];
markers[i] = new google.maps.Marker({
title: details.name,
position: new google.maps.LatLng(details.location[0],details.location[1]),
locCode: details.locCode
});
markers[i].setMap(map);
var thisMarker = markers[i];
google.maps.event.addListener(thisMarker, 'click', (function(thisMarker, i, details) {
// self calling fun开发者_Go百科ction was the key to get this to work
return function() {
$.ajax({
url: 'js/locations/'+details.locCode+'.js',
dataType: 'script',
success: function(data) {
// do my specific stuff here, basically adding html to the info-window div via jQuery
// set the content, and open the info window
infoWindow.setContent($("#info-window").html());
infoWindow.open(map, thisMarker);
}
});
}
})(thisMarker, i, details));
}
}
Check out my answer here:
Jquery Google Maps V3 - Information window is always fixed to one marker
I think this will help resolve your issue.
Bob
精彩评论