I wonder why I'm getting undefined values ?? So basically I'm using google map api to obtain the time traveled between 2 points. When i try to alert the value with
alert(response.routes[0].legs[0].duration.value / 60);
All works fine i got the values, but when i try to assign this value to a variable and alert it, it gave me "undefined". Below is the javascript code
function travellingTime(Origin,Destination){
var Time;
var directionsService = new google.maps.DirectionsService();
var request = {
origin: Origin,
destination: Destination,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
// Display the distance:
//alert(response.routes[0].legs[0].distance.value + " meters");
// Display the duration:
Time = (response.routes[0].legs[0].duration.value / 60);
}
});
alert(Time) ;
//app.setTime(String(Time))
}