如何在同一张地图上显示两条路线? 示例:A-> B y C-> D。 使用Google Maps API。
function calcRoute1() {
var start = 'Huanchaco-Trujillo';
var end = 'Lince-Lima';
var request1 = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request1, function(response1, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response1);
}
});
}
function calcRoute2() {
var start = 'Chiclayo-Lambayeque';
var end = 'Tacna-Tacna';
...
}
答案 0 :(得分:1)
这对我有用:
var directionsService1 = new google.maps.DirectionsService();
var directionsDisplay1 = new google.maps.DirectionsRenderer();
function calcRoute1() {
var start = 'Huanchaco-Trujillo';
var end = 'Lince-Lima';
var request1 = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService1.route(request1, function(response1, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay1.setDirections(response1);
directionsDisplay1.setMap(map);
}
});
}
var directionsService2 = new google.maps.DirectionsService();
var directionsDisplay2 = new google.maps.DirectionsRenderer();
function calcRoute2() {
var start = 'Chiclayo-Lambayeque';
var end = 'Tacna-Tacna';
var request2 = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService2.route(request2, function(response2, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay2.setDirections(response2);
directionsDisplay2.setMap(map);
}
});
}
google.maps.event.addDomListener(window, 'load', load);