Adding an onclick event to google.map marker

前端 未结 6 573
说谎
说谎 2020-12-24 02:20

I\'m stuck trying to figure out a little bit of JS :( I have a google map

var myCenter=new google.maps.LatLng(53, -1.33);

function initialize()
{
var mapPro         


        
6条回答
  •  [愿得一人]
    2020-12-24 02:32

    In my case, I have multiple markers and I wanted to know which marker was clicked. I found following solution on google forum - https://groups.google.com/g/google-maps-js-api-v3/c/cAJrWZWdD-8?pli=1

    By Chris Broadfoot (Google Employee)

    You can reference the clicked marker with 'this':

    google.maps.event.addListener(marker, 'click', markerListener);

    function markerListener() { alert(this.getPosition()); // this.setIcon(... }

提交回复
热议问题