I use google maps for my website, i want to get directions during traffic, how can i get estimated time during traffic in google maps directions ?
i use the following code to get directions without traffic.
function direction(){
var directionsService = new google.maps.DirectionsService();
var directionsRenderer = new google.maps.DirectionsRenderer();
var nmap = new google.maps.Map(document.getElementById('direction-map'), mapOptions);
directionsRenderer.setMap(nmap);
calcRoute();
}
function calcRoute() {
var blng = parseFloat($("#beginning-lng").val());
var blat = parseFloat($("#beginning-lat").val());
var dlng = parseFloat($("#destination-lng").val());
var dlat = parseFloat($("#destination-lat").val());
var start = new google.maps.LatLng(blat, blng);
var end = new google.maps.LatLng(dlat, dlng);
var request = {
origin: start,
destination: end,
travelMode: 'DRIVING',
avoidTolls: true
};
directionsService.route(request, function (result, status) {
if (status == 'OK') {
directionsRenderer.setDirections(result);
console.log(result);
var distance = result.routes[0].legs[0].distance.value / 1000;
var time = result.routes[0].legs[0].duration.value / 60;
}
});
}