Add class to marker on click

对着背影说爱祢 提交于 2019-12-24 11:35:10

问题


On Google Maps I would like to add a class to the marker when clicking on it. I've searched the API but I can't find a solution. Do you have any leads?


回答1:


Use addListener:

var marker = google.maps.Marker({
    position: geolocation
});

google.maps.event.addListener(marker, 'click', function() {
    // your code
});



回答2:


in fact, at this level I do not have to worry, but the concern is how to add a class marker.

thank you

google.maps.event.addListener(marker, "click", function (e) {
    var curMarker = this;
    console.log( curMarker );
    curMarker.class = "myClasse"; // Exemple
}); 

butit does not work




回答3:


google.maps.event.addListener(marker, 'click', function() {
    marker.set("class", "className");
});

u can also do this while creating a marker

marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lng),
    map: map,
    class:'className'
    draggable: true
});


来源:https://stackoverflow.com/questions/22537626/add-class-to-marker-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!