【问题标题】:giving color of path in google directions api在 google 方向 api 中给出路径的颜色
【发布时间】:2014-04-25 11:32:34
【问题描述】:

https://developers.google.com/maps/documentation/javascript/directions

这是我显示路径的代码

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);
    }
  });
}

如何更改路径颜色默认为蓝色?

【问题讨论】:

    标签: javascript google-maps google-maps-api-3 directions


    【解决方案1】:

    你可以在API Reference找到这个

    DirectionsRendererOptions 对象采用 polylineOptions 属性,您可以在其中定义其样式。

    例如:

    var directionsOptions = {
        polylineOptions: {
            strokeColor: 'red'
        }
    }
    
    directionsDisplay = new google.maps.DirectionsRenderer(directionsOptions);
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      当您向地图添加折线时,您可以简单地使用PolylineOptions 对象,并在其上调用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);
      

      【讨论】:

        猜你喜欢
        • 2017-07-09
        • 2016-08-01
        • 2014-03-25
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-23
        • 1970-01-01
        相关资源
        最近更新 更多