Change route (road) color from google maps

Asked

Viewed 1,198 times

1

mudar linha de marcação do google maps, mudar cor da rota no google maps api

Someone can help me how you change that blue color of the road when you set a course.. I already have the style all ready just don’t know the variable that applies to that part of the map.. Obg


 /*Estilizando o mapa;
  Criando um array com os estilos*/
  var styles = [

  ];

 /*crio um objeto passando o array de estilos (styles) e definindo um nome para ele*/
  var styledMap = new google.maps.StyledMapType(styles, {
    name: "Mapa Style"
  });

  /*Aplicando as configurações do mapa*/
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');
  });

1 answer

1

To change the color, it is necessary to 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 */
    }
});

As you should already have the code that makes the route, I will leave only a low example.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.