Skip to content Skip to sidebar Skip to footer

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?

Solution 1:

Use addListener:

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

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

Solution 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

Solution 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
});

Post a Comment for "Add Class To Marker On Click"