trigger google maps marker click

前端 未结 2 633
心在旅途
心在旅途 2020-12-24 10:54

I have a google map set up to find the user\'s current location, and center the map at that closest marker to their location. The markers, when clicked, open up an infobox (

相关标签:
2条回答
  • 2020-12-24 11:24

    i see that this question has been sitting for quite awhile, but, just in case, this answer may be helpful: trigger google maps marker click

    The code would look like this:

    var marker = new google.maps.Marker({});
    new google.maps.event.trigger( marker, 'click' );
    

    Good luck!

    0 讨论(0)
  • 2020-12-24 11:25

    I found I needed to attach a click event to the marker like so

    var marker = new google.maps.Marker({});
    marker.addListener('click', function() {
        infowindow.open(map, marker);
    });
    new google.maps.event.trigger( marker, 'click' );
    
    0 讨论(0)
提交回复
热议问题