Isaias Hoyos Isaias Hoyos - 1 year ago 230
Javascript Question

Why Google Maps Polyline strokeColor always black?

I have already draw some trajectories in Google Maps Api. But I want to give a different color to each trajectory. The problem is that the color always is black even when strokeColor is not '#0000'. Any ideas about what is happening? Here is my code:

<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
html, body {
height: 100%;
margin: 0;
padding: 0;
#map {
height: 100%;
<div id="map"></div>

function initMap() {

var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: {lat: -12, lng: -77},
mapTypeId: google.maps.MapTypeId.TERRAIN

var aristas ='aristas.geojson');
var aristasPath = new google.maps.Polyline({
path: aristas,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2


Answer Source

You are adding your polyline to the data layer with .loadGeoJson, that needs to be styled using the data layer styling methods, not as a normal google.maps.Polyline

// Set the stroke width, and fill color for each polyline/polygon{
  strokeColor: '#FF0000',
  strokeOpacity: 1.0,
  strokeWeight: 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download