Reputation: 1945
google.maps.event.addListener(marker2, 'click', function() {
infowindow2.open(map,marker2);
});
I need this function to be called on load of the page and not on click of marker2
I have seen Trigger click function on load however the syntax appears to be different. So i tried the following
I have tried several compinations, but can't seem to get the syntax right. could somebody please explain how to do this, and break down the code for myself and others to learn from
Thanks
Upvotes: 0
Views: 129
Reputation: 138
Your page loading just once, use addListenerOnce.
google.maps.event.addListenerOnce(map, 'idle', function() {
infowindow2.open(map,marker2);
});
Upvotes: 1
Reputation: 5788
If you want the infowindow to be open on page load, I think rather than triggering a click to open it - you'd be better off if you just called the open
function right after creating your infowindow object.
var infowindow2 = new google.maps.InfoWindow(infoWindowOptions); //create your infowindow object with desired options
infowindow2.open(map, marker2); //call the open method right after creating your infowindow object
You can then add the listener for the click on the marker as well.
Upvotes: 1
Reputation: 161334
This should work if marker2 exists (has been created) before it is called:
google.maps.event.trigger("click", marker2);
Upvotes: 0