Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set colour of a Polyline in Google Maps v3?

How can I set the colour of a Google Maps Polyline?

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

The above doesn't show up as an error in Firebug, but it doesn't change the color either.

Thanks for your help.

like image 360
Richard Avatar asked May 31 '11 21:05

Richard


People also ask

How do I get custom colors on Google Maps?

5. Click to enable the “Visibility” option under the Stylers header. Enable the “Hue” option, then select a color for the feature type you want to color on the rainbow color selector. Wait a few seconds for the Styled Maps Wizard to apply the color changes and re-render the map page in your browser.

How do I color code a saved place on Google Maps?

Hover over each to see what it signifies. If you can't find the icon you want, type it into the “filter box” – it should pop up. 10. To color-code your map, just use the same method for the icons – click on the destination and when the box pops up, just click on whatever color you want to make it.


2 Answers

Basically looks correct to me. However, if this is your code verbatim then you immediately overwrite the color. Hence, I guess you are getting a blue polyline from the start. Try setting a timer to see the transition:

setTimeout(function () {
    myRoutePath.setOptions({strokeColor: 'blue'});
}, 3000);
like image 98
mhyfritz Avatar answered Sep 30 '22 20:09

mhyfritz


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

myRoutePath.setOptions({strokeColor: '#0000FF'});
like image 25
Daniel Avatar answered Sep 30 '22 19:09

Daniel