I would appreciate some help with a couple of issues I am stuck on. I have managed to get a response from the Google directions API where I Have a start location, a way point and a destination. I want to use the lat and lng values returned to plot a polylione on a map.
My problems are, I dont know how to parse the response to get all the lat and lng values returned. I can see the “path” through the response is routes - legs - steps but there are two steps sections and I dont know how to include both. I also confess I dont really understand how lists work and I have been trying to show my results in a list viewer just to prove I Have correctly parsed the returned file.
I have attached the sample google response file for your information.JSONDIrections.txt (8.9 KB)
Can anyone tell me how I parse the file to get all the latitude and longitude records in order from both steps sections of the attached file.
It looks like you’ll want to get the property “routes” from “JSonDirectionsText” (the JSON object), then take the first list item from that, then take the legs property from that, then take the first list item from that, then take the end_location property from that, and finally, take the lat (or lng) property from that. Phew!
Each bracket [ is the start of a list so when you see that, you know you have to get the first (or sometimes a different index) list item.
I can work up some blocks later if you need them but try that and let me know how it works…
I would suggest trying to get a single value before attempting a loop.
Hi, Thanks for looking into this for me. I would appreciate some blocks if you can as I have been looking at this for a long while and confess to being completely stumped.
You’re welcome. You should get back 51.7068738. And I was able to copy the JSON text into a variable and test it and verified that it did display 51.7068738.
Wow that is awesome. Thank you for taking the trouble to explain it to me. What I am doing is writing a sort of Uber app for a friend of mine. I have a customer app and a driver app. The customer requests a taxi from his current location to a destination of his choice. With the driver app the driver can choose to accept the job or decline it. This all works fine so far. What I then want to do, when the driver accepts the job is to show a map to the driver using the driver location as the start point, the customers location as the way point and the customer destination as the final point. During testing i play the part of both people whihc is why the first location and the way point are both at highlands park. I think if I drive out with my iphone and request a taxi and then return home and accept the job as the driver at my home I will get a response file in the same format that make more sense as well. Thought you might like the background.
This is going to take me a while to work through but can I ask for one more piece of advice. How would you loop through the file as the number of step by step directions will change for every route requested. I dont like the idea of using an artificially high loop value as I just see that causing an error when it gets to the end of the file. Is there a DO While NOT End Of File or equivalent in Thunkable that you know of?
Thanks again for the trouble you have taken to help me.
I really like the “for each item j in list” block but if you need to know which index # it lands on at some point, then you have to manually increase a counter variable value by 1 each iteration of the loop. The “count with i” block does that for you since you can use “i” as the index value.
Ive started to stumble a little sooner than I had hoped. I have the starting latitude and longitude ok and I can now show those in the app as detailed in the screenshot. What I think would be useful is a count of the items in the steps list. Using JsonFormatter as you advised I can see the first steps list contains 7 items but the Json provided by Google doesn’t have this information. If I run the blocks as shown here I get a steps=0 result. I presume JsonFormatter works this out somehow. Do you know how I might be able to count this.
can you tell me how to do it i thought to make it but then i thought it cant happen but now i saw this topic can you please explain me because i did not got how to use it as you said