I am working with Google maps and want to plot some polylines. The number of points will be variable and I am parsing the results from google directions API to build my lists. I have two lists, one with latitudes and one with longitudes. The blocks below do not produce anything I can see on the map.
Does anyone know why? There is very little data I can find to describe what information is expected in the coordinates property.
Do I need to build 4 lists with lat start points, long start points, lat end points and long end points?
Any advice would be welcome.
You will need something like this
Notice how I add ZERO to the latitude and longitude. Thunkable has a nasty tendency to convert numeric values into strings.Adding zero forces them back to numbers.
Although it does not appear in this example, there is always the possiblity of the list of latitude and the list of longitude to get out of wack and have different lengths. If that happens, the screen will go blank. So be careful.
Thanks for your replies guys. You have both given me something to think about.
I reviewed the help available online and decided to stick as closely to it as I could. I came up with these blocks which resulted in a polyline from my location to the North Pole!. The actual line expected should only be about 20 meters long.
I added the following blocks to see the length of the two lists I am working with. This appears just before the count with block above.
When I run this a get a list length of one while you can see in the output below, there are two items in each text list, one of which is lost when the list is made.
The red line in the bottom corner starts from where I expect goes NORTH!!
Question. When I make the lists from the text string, I strip off the trailing comma before I do it. Does that need to be on the text string for the list to include both items.
I hope all that is clear.
A few things that jump right out
The way you are getting the length of list is causing some issues. You are actually nesting the lists, so there is just one list. Try this change in the count loop, as well as your debugging code
The Length Of List block has been broken for months. It return not a list of elements, but a list of every character in the list. This is what I use instead:
Loops of lists can be tricky (because of Thunkable oddities). I would recommend INSIDE the loop, set a variable to the list of coordiate for which you want to draw the line. Use the Make Text From List block to display the list. Then try to draw the poly line. using that variable as the coordiate property.
My guess is that you are getting a single character in one of those latitude fields.
Thanks for this. I have a bit of a block where lists are concerned so this is very helpful. Whats not so nice is hearing the length of list function is broken. Do we know if there are any plans to fix it?
No idea. I thought I added a github ticket, but I couldn’t find it. Probably wouldn’t hurt to add one.
Hi, just wanted to add the nesting of lists was a real problem. When I undid this I was able to get the thing working as intended.
I thought you might like to know that it looks like the length of list issue has been fixed. At least it is working for me.