May I know a way to change the Google Map marker color via Javascript.. I am new at this and any help would be much appreciated, Thank you.
I used the following code
To expand upon the accepted answer, you can create custom MarkerImages
of any color using the API at http://chart.googleapis.com
In addition to changing color, this also changes marker shape, which may be unwanted.
const marker = new window.google.maps.Marker(
position: markerPosition,
title: markerTitle,
map: map)
marker.addListener('click', () => marker.setIcon(changeIcon('00ff00'));)
const changeIcon = (newIconColor) => {
const newIcon = new window.google.maps.MarkerImage(
`http://chart.googleapis.com/chart?
chst=d_map_spin&chld=1.0|0|${newIconColor}|60|_|%E2%80%A2`,
new window.google.maps.Size(21, 34),
new window.google.maps.Point(0, 0),
new window.google.maps.Point(10, 34),
new window.google.maps.Size(21,34)
);
return newIcon
}
Source: free udacity course on google maps apis
You can use the strokeColor
property:
var marker = new google.maps.Marker({
id: "some-id",
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
strokeColor: "red",
scale: 3
},
map: map,
title: "some-title",
position: myLatlng
});
See this page for other possibilities.
var map_marker = $(".map-marker").children("img").attr("src") var pinImage = new google.maps.MarkerImage(map_marker);
var marker = new google.maps.Marker({
position: uluru,
map: map,
icon: pinImage
});
}