Hi!
Im currently using this code to calculate the route and display it.
BUT I need help on with theese two things.
First off: Does anyone have a code example of how to add together a trips
distance, currently its displayed per Leg
Secondly: How can I do to get the total duration of the trip, including both
legs?
function calcRoute() {
var start = initialLocation; //document.getElementById("latlng").value;
// var end = document.getElementById("end").value;
//var waypt = waypointen;
var waypts = [];
//waypoint check
if (waypointen == undefined)
{
alert("Waypoint har inget värde, se värde till höger" + waypointen)
}
//Med värde kör directions
else {
alert("Wapointen har fått ett värde" + waypointen + " fyller på array
med fakta")
waypts.push({
location:waypointen,
stopover:true});
alert("Arrayen har fyllts på med följande fakta" + waypts[0])
};
//waypts[0] = waypointen;
alert("Från: " + start + "Förskola: " + waypts + "Till:" + end2);
var request = {
origin:start,
destination:end2,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById("directions_panel");
summaryPanel.innerHTML = "";
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment +
"</b><br />";
summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br
/>";
//här lägger du totala längden!
}
//Skicka värdena till computetotaldistance
//computeTotalDistance(directionsDisplay.directions);
}
});
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.