我无法使用DirectionsService.route
设置为provideRouteAlternatives
且定义了多个true
的{{1}}来获取替代路线。
但the doc中没有任何内容表明这是不可能的。所以,我只是不走运,还是你也经历过同样的问题?
(当我删除航点时它确实有效......)
因为有些人要求我实施,所以我快速jsFiddle显示了问题。检查控制台日志以查看带有和不带路点的结果。
waypoints
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();
答案 0 :(得分:0)
感谢您提醒我们。
这似乎是一个文档问题。我们提供替代路线 对于没有优化的查询:true和没有waypoint。
我们要求更新文档。