Alex Rivera | Logout

Google maps-api v3 InfoWindow automatically open on page load

Asked 2012-04-26T23:51:27.597
23

I am working on a project where I am using the Google Maps api-v3 , On the map there will be a few place markers containing information that I am storing in an InfoWindow.

I am wondering is there anyway that you can set an InfoWindow to automatically open on the page load (i.e automatically open without user interaction).

Searching online all I can seem to find is that it needs to be tied to an event listener but all the events the InfoWindow object seems to have are mouse events.

Does anyone know of a workaround of sorts ?

Edit
Report

1 Answer

12

I am very late for this question but I wanted to share something.I also searched for its solution and even did not get working from the above solution. Then I tried myself and got my own solution (I am not expert and my idea may not be good but working fine for me). we generally do like

var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', (function(marker) {
return function() {
    infowindow.setContent('some content here');
      infowindow.open(map, marker);
    }
})(marker));

replace the above lines with:

var infowindow = new google.maps.InfoWindow();
infowindow.setContent('some content here');
infowindow.open(map, marker);

dont wait for the click event of marker simply set the content and open it (you must define the map and marker and infowindow points to your marker).

answered 2012-08-09T21:21:49.600

Your Answer