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