Calculation of itinerary time?

Hello everyone,

I have a question. Is it possible in Glide to calculate the time of the itinerary between two addresses by selecting the type of transport (bike, car, commun transport etc) like we can do it in GoogleMap?

Thanks in advice for your answers.

1 Like

As of now it’s not possible, but a script in Google Sheets can return what you want, albeit you have to take into account that there’s a limit of calculation request per day and a lag to update that data to your app.

Thank you for the answer and sorry for my belated replay.
I’m not sure that (or I don’t know yet how) we can count the spending time by transport between two addresses in Google Sheets. For exemple, I need to do the request linked to filled data by user for planning:
I know that the person 1 is at 2 p.m in address 1. I need to be sure that this person 1 can be at 3 p.m. (and not later) in address 2 and he uses the bicycle. The same request for the person 2 who uses the bus, for example, etc. The calculation should tell me , for exemple: the person 1 can arrive at 3 p.m. in the address 2/ the person 2 can arrive at 2. 50 p.m. (or at 3.15 p.m.) in the address 2 etc…

I know that Google map propose to intergrate to application the requests but I am not sure that we can intergrate it to Glideapps.

Thanks again for your answer.

This needs a script of its own.

Go to Tools > Editor and add this script to your dashboard.

/**
* Get the distance between 2 different addresses.
* @param {string} origin_address The origin/start address as string Eg. "102 Petty France, London, SW1H 9AJ".
* @param {string} destination_address The destination/end address as string Eg. "10 Whitechapel High Street, London, E1 8QS".
* @param {string} travel_mode The mode of travel as string. Default: DRIVING. Options: BICYCLING, TRANSIT, WALKING.
* @param {string} return_type The return type as string. Default: MILES. Options: KILOMETERS, MINUTES, HOURS, STEPS.
* @return the distance between 2 different addresses.
* @customfunction
*/
function GOOGLEDISTANCE(origin_address,destination_address,travel_mode,return_type) {
  Utilities.sleep(1000);
  
  var travelMode = "";
  
  switch(travel_mode) {
case "BICYCLING":
case "bicycling":
  travelMode = Maps.DirectionFinder.Mode.BICYCLING;
  break;
case "DRIVING":
case "driving":
  travelMode = Maps.DirectionFinder.Mode.DRIVING;
  break;
case "TRANSIT":
case "transit":
  travelMode = Maps.DirectionFinder.Mode.TRANSIT;
  break;
case "WALKING":
case "walking":
  travelMode = Maps.DirectionFinder.Mode.WALKING;
  break;
default:
  // Default to driving
  travelMode = Maps.DirectionFinder.Mode.DRIVING;
  //return "Error: Wrong travel mode";
  }

  // var auth = Maps.setAuthentication(clientId, signingKey);
  
  var directions = Maps.newDirectionFinder()
  .setRegion('UK')
  .setLanguage('en-GB')
  .setOrigin(origin_address)
  .setDestination(destination_address)
  .setMode(travelMode)
  .getDirections();

  if (directions.status !== "OK") 
return 999999
  
  var route = directions.routes[0].legs[0];
  var time = route.duration.value;
  var distance = route.distance.value;
  
  var steps = route.steps.map(function(step) {
  return step.html_instructions.replace(/<[^>]+>/g, "");
  }).join("\n");
  
  switch(return_type) {
case "MILES":
case "miles":
  return distance * 0.000621371;
  break;
case "KILOMETERS":
case "kilometers":
  return distance / 1000;
  break;
case "MINUTES":
case "minutes":
  return time / 60;
  break;
case "HOURS":
case "hours":
  return time / 60 / 60;
  break;
case "STEPS":
case "steps":
  return steps;
  break;
default:
  // Default to miles
  return distance * 0.000621371;
  //return "Error: Wrong return type";
  }

}

Then go back to your Sheet, for every itinerary calculation you can call a function like this.

=GOOGLEDISTANCE(A2,B2,"bicycle","minutes")

With A2 being the origin, B2 the destination.

3 Likes

Waw! Thank you for this explication and solution! :pray: :star_struck:
It is true, I haven’t thought about writing my own script yet. :thinking:

2 Likes

Let me know if you need further help to set this up, I will help :wink:

2 Likes

Thank you :slight_smile:

1 Like