我有一个关于方向服务API的问题。有没有一种混合出行模式设置,可以让我为一辆自行车画一条路线,即使那条特定的街道上没有自行车道,或者这违反了街道规则(这是否可能)。我想画一条从A到B的线段,准确地穿过选定的道路,如果那条道路实际上不允许在那个方向上行驶,就不能绕着它走。它不一定要在驾驶规则方面是正确的,它必须只是画在街道上。我尝试了自行车模式,而不是驾驶模式,但没有任何区别。
我希望我的帖子有任何意义
调用示例:
function loadRoute0() {
var request0 = {
origin: new google.maps.LatLng(46.56300788, 15.62779705),
destination: new google.maps.LatLng(46.55953332, 15.62616729),
travelMode: google.maps.TravelMode.BICYCLING
};
directionsService.route(request0, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
var renderer = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: "#00FF00"
},
suppressMarkers: true,
map: map
});
renderer.setDirections(result);
}
});
}
发布于 2018-06-10 03:40:45
你可以使用TravelMode.WALKING
,它倾向于给出对TravelMode.DRIVING
不起作用的单向道路和其他路线的结果。问题中的代码不会复制您发布的图片,但使用TravelMode.WALKING
会返回一条路径(其中TravelMode.BICYCLING
为发布的代码提供ZERO_RESULTS
)
function loadRoute0() {
var request0 = {
origin: new google.maps.LatLng(46.56300788, 15.62779705),
destination: new google.maps.LatLng(46.55953332, 15.62616729),
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request0, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
var renderer = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: "#00FF00"
},
suppressMarkers: true,
map: map
});
renderer.setDirections(result);
} else
console.log("status=" + status);
});
}
代码片段:
var map;
function initialize() {
map = new google.maps.Map(document.getElementById("map_canvas"));
directionsService = new google.maps.DirectionsService();
loadRoute0();
function loadRoute0() {
var request0 = {
origin: new google.maps.LatLng(46.56300788, 15.62779705),
destination: new google.maps.LatLng(46.55953332, 15.62616729),
travelMode: google.maps.TravelMode.WALKING
};
var markerS = new google.maps.Marker({
position: request0.origin,
map: map,
label: "S"
});
var markerE = new google.maps.Marker({
position: request0.destination,
map: map,
label: "E"
});
directionsService.route(request0, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
var renderer = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: "#00FF00"
},
suppressMarkers: true,
map: map
});
renderer.setDirections(result);
} else
console.log("status=" + status);
});
}
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
https://stackoverflow.com/questions/50777351
复制相似问题