0

I want to calculate the drive time using the distance matrix API - while doing so I need to calculate the drive time at specific times of the day and therefore I'm using the departure_time parameter. However, I can't seem to figure out the correct format that I need to specify the time in. When I set departure_time=now in the API URL works fine. But when I try to specify a time, say 1pm, I get an error Invalid request. Invalid departure_time parameter.

For example, the following URL works fine (API key removed) - https://maps.googleapis.com/maps/api/distancematrix/json?origins=53.542416,-1.437382&destinations=54.552902,-6.000198999999999&key=XXXX&mode=driving&departure_time=now

But this one doesn't - https://maps.googleapis.com/maps/api/distancematrix/json?origins=53.542416,-1.437382&destinations=54.552902,-6.000198999999999&key=XXXX&mode=driving&departure_time=2021-09-21T13:00:00.00000Z

Can someone please advise on what's the best way to achieve this? Thanks

Chipmunk_da
  • 467
  • 2
  • 9
  • 27

2 Answers2

0

The parameters arrival_time and departure_time should be given as a timestamp, seconds after 1970-01-01 00:00:00.

E.g. in python this is done by calling date.timestamp() on a datetime-object.

Aerows
  • 760
  • 6
  • 22
0

The departure time should be a timestamp expressed in seconds. in Javascript, something like `let newDate = new Date(currentYear,currentMonth,currentDay,prevHour,prevMinutes);

let timeinSeconds = newDate.getTime()/1000;` Will give the departure time expressed as a timestamp in seconds then can be supplied in place of "now"