Getting driving time from google maps

Hi guys, can someone tell me what I'm doing wrong? I'm trying to get the driving time between 2 points.

The key has no restrictions, the Google Maps APIs are all enabled.

with key removed for post...

{
  "request": {
    "url": "https://maps.googleapis.com/maps/api/distancematrix/json?key=xxxxx",
    "credentials": "same-origin",
    "headers": {
      "Authorization": "---sanitized---"
    },
    "method": "GET"
  },
  "response": {
    "data": {
      "destination_addresses": [],
      "origin_addresses": [],
      "rows": [],
      "status": "INVALID_REQUEST"
    },
    "headers": {
      "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
      "cache-control": [
        "no-cache",
        "must-revalidate"
      ],
      "connection": "close",
      "content-length": "113",
      "content-type": "application/json; charset=UTF-8",
      "date": [
        "Mon",
        "06 Mar 2023 13:07:55 GMT"
      ],
      "expires": [
        "Fri",
        "01 Jan 1990 00:00:00 GMT"
      ],
      "pragma": "no-cache",
      "server": "mafe",
      "server-timing": "gfet4t7; dur=34",
      "vary": "Accept-Language",
      "x-frame-options": "SAMEORIGIN",
      "x-xss-protection": "0"
    },
    "status": 200,
    "statusText": "OK",
    "ok": true,
    "url": "https://maps.googleapis.com/maps/api/distancematrix/json?key=xxxxx"
  }
}

From Google...

the first screenshot says that origins should be of type array but I don't know what format it need - is the data you're sending in the right format?

As far as I can tell it is. They accept a few options and I've tried most of them; lat/lon, addresses, Place IDs which require prefixing with a keyword. The API Request section looks like it's not even sending any data with the request?

Hey @CarlaK!

Happy to help here. If you're just looking to find the distance between two points, then I think you might need to use origin and destination, which both accept a string of a lat long.

https://developers.google.com/maps/documentation/javascript/directions#DirectionsRequests

In your screenshot, you're passing in an array of a lat long string. If you want to pass in just the string, you could do something like {{table2.data.map(row=>row.locat)}}

Let me know if that helps at all!

Hi @victoria

I'm using the distance matrix because I will usually have more than one origin, but just one destination. All I need is the Duration because I'm trying to get ETAs for my tracked courier cars that are returning to base.

Using your link above and swapping to the distance matrix page, the parameters that it is asking for don't seem to match up with the parameters that Retool is asking for:
image

Retool:

I'm still learning JavaScript and json and Retool, so apologies if I'm just doing things wrong. I've tried every different way of inserting the data that I can find, and it still comes back with invalid_request.

Hmm it looks like your origins and destinations values aren’t turning green / actually evaluating as arrays. Maybe that’s our problem! :slightly_smiling_face::crossed_fingers: If so, should be a quick fix. Mind if I step into your app to take a look? The name of your app would be helpful!

Hi @victoria , I sent you the details in a private message if you get a chance to have a look :slight_smile: