Adding an eta / arrive by time

I need to create an ETA from current location to a specified location.

I know how to calculate duration, but can’t seem to pull that information to add it to the current time. I would also need to make the ETA a static value for the desired workflow.

Any suggestions will be greatly appreciated. :slight_smile:

Not sure if you looked too hard, but you don’t need to reinvent the wheel!

Distance Matrix API overview | Google for Developers

Thank you for your kind and encouraging words @GH5T.

I have, in fact, looked quite diligently. And, I am most certainly not trying to reinvent the wheel. As noted in my post, I am capable of acquiring the travel duration. My goal is to provide a time of day based on the travel duration, not just a duration of travel. If I have missed that option with Distance Matrix, would you be so kind as to enlighten me?

To provide a time of day based on travel duration, you would typically need a mapping or routing service that can estimate the travel time between two locations. Google Distance Matrix API can be a suitable option for this purpose.

Here’s a general outline of how you could achieve this using the Google Distance Matrix API:

  1. Set Up Google Distance Matrix API:
  • Go to the Google Cloud Console.
  • Create a new project or use an existing one.
  • Enable the Distance Matrix API for your project.
  • Obtain the API key.
  1. Use the API Key in Your Application:
  • Integrate the Google Distance Matrix API into your application or script.
  • Make a request to the API with the origin and destination coordinates.
  • Extract the travel duration from the API response.
  1. Calculate Time of Day:
  • Based on the estimated travel duration, calculate the expected time of arrival (ETA).
  • Add the travel duration to the current time to get the expected arrival time.
  • Optionally, consider factors like traffic conditions, time of day, and historical data to improve accuracy.
  1. Display or Use the Time of Day:
  • Once you have the estimated arrival time, you can display it to the user or use it for further processing in your application.

My duration is formatted as text. My issue is trying to add the duration to the current time with it being text.

If it’s formatted as text, you can convert it to a number as well, then base your calculations off that.

1 hr 35 mins, when converted to a number, results in 135.

I guess this is where I do feel like I am recreating the wheel. :confused:

I am honestly feeling like I am digging myself into a mathematical hole, and still failing to achieve the desired result.

ChatGPT win :joy:

Are you certain the API only provides the text duration? I’d expect there to be a minutes value or hour decimal as well as the formatted text.

Edit: I just checked and it returns the number of seconds the journey takes next to the text value.

“duration”: { “text”: “3 jours 16 heures”, “value”: 318119 }


Clearly overthinking on my end… :face_with_diagonal_mouth:

Thank you!