Reputation: 45
i am using bellow code to open up a infowindow in my map
//populate the infowindow to defined marker map point
function assignmarkerclick(marker1, index, message) {
google.maps.event.addListener(marker1, 'click', function () {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent(message);
infowindow.open(map, marker1);
});
}
// Shows the info window for the specified marker
function showMarker(index) {
new google.maps.event.trigger(marker[index], 'click');
}
so when i click on the "show point" (assuming i am calling the showMarker() javascript function "show point link" click event) link at first time info window wont open ,when i click on the "show point " link second time info window will open, has any one had this bug before ? could some one help me to sort this issue please ?
thanks
Upvotes: 0
Views: 1454
Reputation: 9407
Create your infowindow object as a global var, outside of the function:
// global var
var infowindow = new google.maps.InfoWindow();
function assignmarkerclick(marker1, index, message) {
google.maps.event.addListener(marker1, 'click', function () {
infowindow.setContent(message);
infowindow.open(map, marker1);
});
}
Upvotes: 3