Greetings to all.
I was experimenting with a new feature for my web app that would show me the actual mileage and travel time, from an origin point to a destination point.
The origin of the example is:
https://maps.googleapis.com/maps/api/distancematrix/json?destinations=Fumone&origins=Anzio&units=metric&key=AIzaSyCLxnSvhGjjVPntRcZPhRDTt4SDZZ5m_PQ
I then inserted the Google URL into a column with a template (see image), taking the start and end path data from two other columns.
Finally, I used a Fetch column, having the template URL as its origin and the JQ Query for the distance described below:
.rows.elements.distance.text
The problem is this: if I try it in the plugin->TransformJson section and run the query with the JSON, everything works. However, if I run it from a Fetch column created for this purpose, it does nothing.
Can anyone explain the arcane?
@Jeff_Hager @Robert_Petitto @ThinhDinh @Darren_Murphy
1 Like
So your fetch JSON with the JQ Query returns nothing?
Nothing, all empty
I have included the link just so you can try it
I’m not getting anything even without the query, so I assume this is a CORS problem. Sorry I don’t have a solution for this, if you’re using user-specific columns to feed the destination and origin.
If they are basic columns instead, I think you can use a HTTP call in Integromat/Make to write the distance and other things back to Glide.
1 Like
Curious, it gives me the result I was looking for
It means no JSON was returned in the app, so there’s nothing for the JQ Query code to work on.
Hola!,
I tested several times and really something wrong happens here.
Looks like Glide has a problem with that API or with that Google’s server.
If you test by using this Glide’s tool Fetch JSON column | Glide, you won’t receive any reply/data
It’s very weird!
Saludos!
1 Like
Thank you for your help. In the end, I opted for a script run directly from Google Sheets, also adding a cache that refreshes every 6 hours, to help me with code calls to Google Maps. In conclusion, one way or the other, the solution is always found!
Here I have found all the solutions that may also be of use to others within this community.
1 Like
You could also try the data → fetch json in which you use this url
in JQuery
You could write
.rows[0].elements[0].distance.text
I think you were missing the 0 element number
1 Like
It doesn’t work that way either
I thank you anyway.
You have to create all the functionality either in Replt or Github and add your API key there. Then use an Experimental column to do it.
The way you’re doing it will not work because of CORS issues.
3 Likes
Thank you very much, I appreciate the help!
Great catch. Many API links are not usable in the fetch column because of the same issue.
1 Like
I found the solution guys! @profxeni @gvalero @Robert_Petitto
Just append https://corsanywhere.herokuapp.com/ to your URL.
For example:
https://corsanywhere.herokuapp.com/https://maps.googleapis.com/maps/api/distancematrix/json?destinations=Fumone&origins=Anzio&units=metric&key=AIzaSyCLxnSvhGjjVPntRcZPhRDTt4SDZZ5m_PQ
Source:
6 Likes
Just to make sure this is not a mistake, you’re showing your Google Maps API key @profxeni . Do you want us to remove it?
1 Like
Great find @ThinhDinh
Does this work with Payhere then?
Thanks for the tip.
I tested like 10 Cors proxies and none worked for me but happy to see it works and can be used.
Saludos Thinh!
https://corsanywhere.herokuapp.com/https://api.payhere.co/api/v1/subscriptions?page=1&per_page=50&access_token=[your_token]
Working for me.
Pass your token in access_token, I was fetching all subscriptions in an account.
3 Likes