Set polyline color in Google Maps v3?

How to set the color of a polyline of Google Maps?

var myRoutePath;
myRoutePath = new google.maps.Polyline({
  path: routeCoordinates,
  strokeColor: "#CC33FF",
  strokeWeight: 3
});     
myRoutePath.setMap(map);
// Reset colour
myRoutePath.setOptions({strokeColor: 'blue'});

The above does not appear as an error in Firebug, but also does not change color.

Thank you for your help.

+5
source share
2 answers

In principle, it looks right to me. However, if this is your code verbatim, you immediately overwrite the color. Therefore, I assume that you get the blue polyline from the very beginning. Try setting a timer to see the transition:

setTimeout(function () {
    myRoutePath.setOptions({strokeColor: 'blue'});
}, 3000);
+2
source

Color names are still not supported as color, use the hexadecimal version instead

myRoutePath.setOptions({strokeColor: '#0000FF'});
+1
source

All Articles