我需要将一条很长的路线分成两部分,一部分使用高速公路而另一部分没有。我编写了两条路线
var request1 = {
origin: startlatlng,
destination: joinLatLng,
waypoints: [{ location: day1 }, { location: day2 }, { location: day3 }],
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
和
var request2 = {
origin: joinLatLng,
destination: endlatlng,
avoidHighways: true,
waypoints: [{ location: day7 }, { location: day8 }, { location: day9 }, { location: day10 }, { location: day11 },
{ location: day12 }, { location: day13}],
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
但是当我使用
绘制每个人时directionsService.route(request1, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
和
directionsService.route(request2, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
仅显示第二个。有没有人对如何连接这两条路线有任何建议?
答案 0 :(得分:5)
directionsDisplay是DirectionsRenderer对象。它一次只能渲染一组方向。如果您创建2个方向渲染器对象,例如directionsDisplay1和directionsDisplay2,则每个渲染器对象可以同时渲染地图上的一半路径