Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google distance api time in minutes

I use google 's distance matrix api to get the distance and time back like this

function calculateDistances() {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
  origins: [from],
  destinations: [to],
  travelMode: google.maps.TravelMode.DRIVING,
  unitSystem: google.maps.UnitSystem.METRIC,
  avoidHighways: false,
  avoidTolls: false
}, callback);
}

the callback gives me back the time and distance.

The problem i have sometimes if the distance is far the time comes back in hours but i always need minutes for a custom calculation method...

How can i fix this problem...

like image 715
MichaelAngelo Avatar asked Oct 18 '25 18:10

MichaelAngelo


1 Answers

Please check the response object you will have two values text and value. Value property has the duration in seconds.

"duration" : {"text" : "19 hours 9 mins","value" : 68914}

like image 191
Ramesh Avatar answered Oct 20 '25 07:10

Ramesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!