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);
}
});
}
如何更改默认为蓝色的路径颜色?
答案 0 :(得分:1)
您可以在API Reference
中找到 DirectionsRendererOptions
对象采用polylineOptions
属性,您可以在其中定义其样式。
例如:
var directionsOptions = {
polylineOptions: {
strokeColor: 'red'
}
}
directionsDisplay = new google.maps.DirectionsRenderer(directionsOptions);
希望这有帮助!
答案 1 :(得分:0)
向地图添加折线时,只需使用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);