简体   繁体   中英

Add class to marker on click

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?

Use addListener:

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

google.maps.event.addListener(marker, 'click', function() {
    // your code
});
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
});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM