google maps api v3 - open infowindow from an external click

后端 未结 2 837
我寻月下人不归
我寻月下人不归 2021-01-05 07:57

So i have a V3 map which is initialised like this:

function init() {
        var mapCenter = new google.maps.LatLng(51.5081289,-0.128005);
        var map =          


        
2条回答
  •  时光取名叫无心
    2021-01-05 08:32

    You don't have to do anything unusual or simulate a click on the marker; just make sure the OpenInfoWindow function can be reached:

    //This is the simple case:
    var myDiv = document.getElementById( "marker25837500" );
    google.maps.event.addDomListener( myDiv, "click", OpenInfoWindow );
    
    //Or if you have other things that you want to accomplish when this occurs:
    var myDiv = document.getElementById( "marker25837500" );
    google.maps.event.addDomListener( myDiv, "click", function() {
        OpenInfoWindow();
        //Do other stuff here
    });
    

    As long as the InfoWindow is in scope (can be reached when the OpenInfoWindow function is called), this should work fine.

提交回复
热议问题