Hi. I am working for a taxi firm. Some of our customers give us only post codes for their location and destination. I am building an app where we can enter the customers current post code and destination postcode and get google maps to first give us the address of both locations and then the distance between them. I am making two api calls to the google geocode api to get the addresses and these are working ok. However the third api call to the distancematrix is returning nothing. No error and " null" in the response and status fields. I have split the blocks that are not working out onto another button to try and narrow down the problem. So my find address button does the first two api calls and the calculate button attemps the third api call and this is the one with the issue.
.Hi,
Does this request work well in the browser?
No, i get the same result. Is there a limit on the number of API calls I can make from a page. The one that fails is the 5th on the page.
Hi @rwplummer1yf4f,
did you activate the distance matrix API in google?
Ive made a new app with nothing but the failing distancematrix call in it. I have hard coded the latitudes and longitudes for now. This fails when I preview it or in the responsive web app as i end up with just a white screen, but appears to work in thunkable live app. Can you advise why this might be
@rwplummer1yf4f If the request doesn’t work in your browser, then the problem is with the request itself. There is no point in making a request in blocks if it doesn’t work even in the browser.
Yes, I have it working in another app and I am using the same credentials this time as well.
See above please
One more time. Show me the browser window where this request is successfully executed and the browser window shows the data.
Sorry I misunderstood perhaps. It only works on my iphone when I run thunkable live but running the live test or the live test responsive web page does not work and I end up with the white screen. However, as it works on my iphone it would suggest that the blocks are not the problem wouldn’t it?
I understand that this request works fine on your iPhone, but it doesn’t work on Android. OK, you can open the Google Chrom browser on your computer and run this query in it. Does it work in the Google Chrom browser on your computer?
No I get the same white screen of death.
Open the panel in the browser by F12 and look at the error message in the console.
What @actech is saying is that when you’re using an API call, you need to be able to run it from a browser window by typing the full url into Chrome (for example) and seeing the data it returns. In your screenshot, it looks like you are storing the full url in app GoogleDistance. I can’t tell because it’s truncated but if it’s a full url with the lat/lon pairs and API key, you need to copy & paste that into a browser window (as if it’s a website you’re trying to go to) and then see what happens. If it works, you should get a JSON formatted response like this:
{
“destination_addresses” : [ “New York, NY, USA” ],
“origin_addresses” : [ “Washington, DC, USA” ],
“rows” : [
{
“elements” : [
{
“distance” : {
“text” : “225 mi”,
“value” : 361715
},
“duration” : {
“text” : “3 hours 49 mins”,
“value” : 13725
},
“status” : “OK”
}
]
}
],
“status” : “OK”
}
If you don’t see that, you’ll likely see an error message. There’s no point in coding anything in Thunkable until you have the API call url working with a valid JSON response. If you’re getting an error message instead, post it here and we’ll see if we can help you.
Google has a sample call url at https://developers.google.com/maps/documentation/distance-matrix/start:
You can just replace YOUR_API_KEY with your actual key and test that as well. That will tell you if your API key is valid but you’ll still then need to try your own full url.
Thanks guys. THe console shows as attached. But when I enter the same string in Chrome I get a response. as shown here.
Simply put, your request works in the browser. But when you run it on Android you don’t get any response and no error messages? And how do you want to get them if I don’t see any blocks on your image that display the error and the result on the device screen?
I have tried error trapping but the app usually crashes before it gets there. The label “labelMiles” is displaying the query result.
I Have added the error trapping as shown here and it shows an error on ANDROID ONLY stating the webside or service provider you are trying to reach does not support HTTPS requests. We know this to be incorrect as according to Google documentation HTTPS is the preferred method and secondly because the app works fine in IOS. Also of interest is the fact the error message is different today from the page not found “404” message I was getting yesterday.
THe blocks including the error trapping are included here. THe app is called Postcode2 and is public if you would like to try it yourself.
You want to make sure you get a 200 status value. Add an If status=200 do [get property blocks] else from Label set Text to Join: Status & Error
Can you post a link to the project? I filtered by your username but couldn’t find it.
The first link is to the mini app (postcodes2)I built just trying to get the distancematrix working so there is nothing else in the app and the start and end point are already set as I got fed up typing them in.
https://x.thunkable.com/projects/5f59e6096f239bf97b8157da/5688ede2-4094-4685-8a0a-a375b3b98451/designer.
The second link is to the app postcodes where I really want this to work!
https://x.thunkable.com/projects/5f553e7941fe930bd6970783/5688ede2-4094-4685-8a0a-a375b3b98451/designer
I joined the status and error messages together using — as the separator and got “The website or service provider you are trying to reach does not support HTTPS requests.—”. So no status message.
If I post the request into chrome, I get a result. If I preview in IOS it works but android seems to be a no go.