kavithma
kavithma

Reputation: 45

info window won't open at first click, instead it will show on second click event

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

Answers (1)

Marcelo
Marcelo

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

Related Questions