Sometimes, we want to change Google Map marker color with JavaScript.
In this article, we’ll look at how to change Google Map marker color with JavaScript.
How to change Google Map marker color with JavaScript?
To change Google Map marker color with JavaScript, we can use the setIcon method or the Marker constructor.
For instance, we write
marker.setIcon("http://maps.google.com/mapfiles/ms/icons/green-dot.png");
to call setIcon with the URL string of the green marker icon.
We can do the same thing when we create the marker with
const marker = new google.maps.Marker({
icon: "http://maps.google.com/mapfiles/ms/icons/green-dot.png",
});
Conclusion
To change Google Map marker color with JavaScript, we can use the setIcon method or the Marker constructor.