API Distance Matrix does not work on thunkable x

Hi Everyone,

I am trying to get the “distance” and the “duration” from google maps distance matrix API, but it is not working. The blocks are shown below:

On the browser, it works:
image

I get the “200” status, but:

On IOS and Android test I get this error message:

I think is a thunkable error… can someone help me please?
Thank you so much!

I am not familiar with the specific API but I wonder why you first post before you get. Is that necessary?

I actually dont know much about html, but I tried only with POST, only with GET and both and with all I got the same result :frowning:

I don’t think you need the Get block. Also, I am a bit sceptical about the way you handle the response. Can you please paste the JSON response in plain text here (not as image) for me to test something? Thanks.

Ok, I will take it out the GET block then. Thank you for answering! It’s here:

{
“destination_addresses” : [ “Nova Iorque, NY, EUA” ],
“origin_addresses” : [ “Washington, D.C., Distrito de Columbia, EUA” ],
“rows” : [
{
“elements” : [
{
“distance” : {
“text” : “367 km”,
“value” : 367440
},
“duration” : {
“text” : “3 horas 49 minutos”,
“value” : 13721
},
“status” : “OK”
}
]
}
],
“status” : “OK”
}

Try this. A more traditional approach. No need to convert the object to JSON as your response is JSON in first place. You need to convert it the other way around actually using the “get object from JSON” block. Give it a go:

Also, start using this tool. It will help you with identifying the paths to the information you need in JSON responses:

https://jsonpathfinder.com

Thank you so much for answering me! However, I am still getting the same message: “something has gone wrong. Check your blocks and reset this page” :frowning:

I don’t know if I do need to set headers like authentication and Bearer acess token key or something like that. I did not put anything on headers.

Can you please share your project link and PM me your API key for me to test? Thanks

I sent to you on private! Thank you :slight_smile:

Two mistakes:

  1. You still do a POST instead of a GET API call
  2. You convert the response to JSON thinking it is an object. The response is JSON as it comes so no need to convert it again to JSON. Thinking that it is an object and converting it to JSON may cause the app to crash.

I mentioned both of the above points in my previous message. Here is the corrected code:

2 Likes

Thank you so much!!! It worked!

1 Like

Hi!!

Do you know why this code does not work on web app?

When I published my web app, I got this error message: “the website or service provider you are trying to reach does not support HTTPS requests”

1 Like

Most API calls do not work on the web app. Yours is just one of those.

1 Like

Hi! thank you for answering it. But it says here on the documentation from the API that "
HTTPS is recommended whenever possible, and is required for applications that include sensitive user data - such as a user’s location - in requests.If HTTPS is not possible, to access the Distance Matrix API over HTTP, use: http://maps.googleapis.com/maps/api/distancematrix/outputFormat?parameters

1 Like

Yes, Google can recommend/require HTTPS but that doesn’t mean that Thunkable can support it as a web app.

2 Likes

Please don’t post in multiple topics.

ok sorry