【发布时间】:2017-02-01 16:08:09
【问题描述】:
我无法使用DirectionsService.route 将provideRouteAlternatives 设置为true 并定义多个waypoints 获得替代路线。
但the doc 中没有任何内容表明这是不可能的。那么是我运气不好还是你也遇到了同样的问题?
(当我删除航点时它确实有效......)
因为有些人要求我实施,我已经完成了一个快速的jsFiddle 来显示问题。检查控制台日志以查看有无航点的结果。
var directionsService;
function initMap() {
directionsService = new google.maps.DirectionsService();
computeFakeItinerary();
}
function computeFakeItinerary() {
var start = {
lat: 45.7579555,
lng: 4.8351209
};
var end = {
lat: 43.7383216,
lng: 7.4069485
};
var waypoints = [{
location: {
lat: 45.18236,
lng: 5.6997148
},
stopover: true
}];
directionsService.route({
origin: start,
provideRouteAlternatives: true,
waypoints: waypoints,
destination: end,
travelMode: 'DRIVING'
}, routeCallback);
directionsService.route({
origin: start,
provideRouteAlternatives: true,
waypoints: [],
destination: end,
travelMode: 'DRIVING'
}, routeCallback);
}
function routeCallback(data, status) {
if (status == 'OK') {
if (data.geocoded_waypoints.length > 2) {
console.log("With waypoints there is " + data.routes.length + " routes");
} else {
console.log("Without waypoints there is " + data.routes.length + " routes");
}
}
}
initMap();
<script src="https://maps.googleapis.com/maps/api/js">
</script>
【问题讨论】:
-
你是怎么做到的?你的代码在哪里?请提供一个 Minimal, Complete, and Verifiable example 来表明您的问题。
-
好的,我会的,但问题与代码无关。
-
如何测试它?怎么会有人帮忙?您甚至没有给出我们可以测试的路线示例。所以是的,请这样做。
-
相关问题:How to Draw Multiple Possible Routes in Google Map from Source to Destination。我同意文档中没有任何内容表明这是不可能的,这使得这要么是文档中的错误,要么是 API 中的错误(我猜该错误在文档中)。您可以尝试创建an issue in the issue tracker
标签: javascript google-maps-api-3 directions google-directions-api