Adding an onclick event to google.map marker

前端 未结 6 589
说谎
说谎 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:54

    Here's what I've done in the past. The only difference I see between my code and yours is that I set the marker map in the marker options, and you're setting in with marker.setMap(Map);

    var marker = new window.google.maps.Marker({
            position: markerPosition,
            map: map,
            draggable: false,
            zIndex: zIndex,
            icon: getNewIcon(markerType != "archive", isBig)
            , animation: markerAnimation
        });
    
    
        window.google.maps.event.addListener(marker, 'click', function () {
            // do stuff
        });
    

提交回复
热议问题