Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在google directions api中提供路径颜色_Javascript_Google Maps_Google Maps Api 3_Directions - Fatal编程技术网

Javascript 在google directions api中提供路径颜色

Javascript 在google directions api中提供路径颜色,javascript,google-maps,google-maps-api-3,directions,Javascript,Google Maps,Google Maps Api 3,Directions,这是我用来显示路径的代码 function calcRoute() { var request = { origin: "Chicago, IL", destination: "Los Angeles, CA", waypoints: [ { location:"Joplin, MO", stopover:false },{

这是我用来显示路径的代码

function calcRoute() {
  var request = {
          origin: "Chicago, IL",
          destination: "Los Angeles, CA",
          waypoints: [
            {
              location:"Joplin, MO",
              stopover:false
            },{
              location:"Oklahoma City, OK",
              stopover:true
            }],
          provideRouteAlternatives: false,
          travelMode: google.maps.TravelMode.DRIVING,
          unitSystem: google.maps.UnitSystem.IMPERIAL
        };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}
如何更改路径颜色默认为蓝色?

您可以在

directionsrenderoptions
对象采用一个
polylineOptions
属性,您可以在其中定义其样式

例如:

var directionsOptions = {
    polylineOptions: {
        strokeColor: 'red'
    }
}

directionsDisplay = new google.maps.DirectionsRenderer(directionsOptions);

希望这有帮助

多段线添加到地图时,只需使用
多段线选项
对象,调用其上的
width()
color()
方法即可:

    private GoogleMap map;

    //get the map reference from the layout

    //Set the polyline configurations
    PolylineOptions rectLine = new PolylineOptions().width(8).color(Color.RED);

    //add the points to the polyline
    rectLine.add(new LatLng(40.3, 18.6));
    rectLine.add(new LatLng(40.3, 20));

    //add the polyline to the map
    map.addPolyline(rectLine);