Javascript 如何更改路线颜色?
我在react Google Maps routes中遇到了更改颜色的问题,我附上下面的代码Javascript 如何更改路线颜色?,javascript,reactjs,maps,Javascript,Reactjs,Maps,我在react Google Maps routes中遇到了更改颜色的问题,我附上下面的代码 { DirectionsService.route({ origin: new google.maps.LatLng(newProsps[0].lat, newProsps[0].lng), destination: new google.maps.LatLng(40.95604847, -73.84254456), t
{
DirectionsService.route({
origin: new google.maps.LatLng(newProsps[0].lat, newProsps[0].lng),
destination: new google.maps.LatLng(40.95604847, -73.84254456),
travelMode: google.maps.TravelMode.DRIVING,
provideRouteAlternatives: true,
}, (result, status) => {
if (status === google.maps.DirectionsStatus.OK) {
if(state.bol){
state.directions = result
}
else{
return null
}
} else {
console.error(`error fetching directions ${result}`);
}
}
我不知道如何在初始化期间更改路由的颜色也许您可以在路由内部使用此代码
directionsDisplay = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: "red"
}
});
directionsDisplay.setOptions({
polylineOptions: {
strokeColor: 'red'
}
});
也许你可以在路线内部使用这个代码
directionsDisplay = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: "red"
}
});
directionsDisplay.setOptions({
polylineOptions: {
strokeColor: 'red'
}
});
有一个你可能感兴趣的老答案有一个你可能感兴趣的老答案