Categories
JavaScript Answers

How to change Google Map marker color with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *