google maps api v3 - open infowindow from an external click

后端 未结 2 824
我寻月下人不归
我寻月下人不归 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:13

    You might use trigger event.

    $('#marker25837500').click(function () {
        google.maps.event.trigger(marker25837500, 'click')
    })
    

    Check this- https://developers.google.com/maps/documentation/javascript/reference#event

    Edit: Also noticed that you are calling onMarkerClick() when marker25837500 is clicked, but you named the other function OpenInfoWindow() so you might need to change that too.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题