Change the color of the route (road) of google maps

1

CananyonehelpmewithhowthisblueroadcolorchangeswhenIsetaroute..IalreadyhavethestyleallreadyIjustdonotknowthevariablethatappliestothatpartofthemap..Obg

/*Estilizandoomapa;Criandoumarraycomosestilos*/varstyles=[];/*crioumobjetopassandooarraydeestilos(styles)edefinindoumnomeparaele*/varstyledMap=newgoogle.maps.StyledMapType(styles,{name:"Mapa Style"
  });

  /*Aplicando as configurações do mapa*/
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');
  });
    
asked by anonymous 11.05.2018 / 07:09

1 answer

1

To change the color, you must use google.maps.DirectionsRenderer . With it you can define some characteristics of the line, for example:

var directionsService = new google.maps.DirectionsService;

const directionsRenderer = new google.maps.DirectionsRenderer({
    draggable: true,
    map: map, /* Objeto google.maps.Map */
    polylineOptions: {
        strokeColor: "#F00" /* Cor em hexadecimal ou nome da cor em inglês */
    }
});

Since you should already have the code that makes the route, I'll leave only one example low.

directionsService.route({
    origin: 'Endereço #1',
    destination: 'Endereço #2',
    travelMode: 'DRIVING',
}, function(response, status) {
    if (status === 'OK') {
        directionsRenderer.setDirections(response);
    }
});
    
11.05.2018 / 08:53