I am developing a random walk app. Users choose a distance to walk and the app returns a random route from the current position, the chosen distance away. I want to ensure that each subsequent choice of destination doesn't backtrack along the same route the user has just walked. I can store the route points in tinydb. They are in the form of a space delimited list of the point's two coordinates in brackets. I figure that if I can check that the last coordinate entry on the stored list is not the same as the first coordinate entry of the list for the new route, then it isn't backtracking. I can do this in,say, python but I'm new to AI and am looking for a little guidance on how to access these variables  last route points coordinates in tinydb, and first ones in the new route.
What have you tried? Please share your Blocks.
You possibly can do something like this after you learn to work with Lists, use the Math Blocks and calculate distance (there are several ways to calculate distance) using App Inventor. The solution to build your app will be complicated.
What you do depends on

how you produce your List of coordinates. Is it a simple list of coordinates or is it a trak (generally a LineString object). You say you store the coordinates in a 'space delimited list of the point's two coordinates in brackets.' What does this mean? All you need is a List of coordinate latitude/longitude pairs.

how you determine the random start. This can be easy, use the pick a random item from Block on your coordinate List. The last coordinate pair in the List is
select list item list (coordinatesList)
index (length of list)
Sajal's tutorial List Blocks On App Inventor  Imagnity is a good example of how to use a List.

the really hard part: how to calculate the distance traversed from a random coordinate to a coordinate x distance away because the user chooses the distance. To get the distance , traverse the set of coordinate pairs, add the distance from the first to the second, the second to the third .. to the last until the distance is approximately the distance the user selects. Another way is to pre calculate the distances and maintain them in a separate List or to make your data set a List of pairs containing the coordinate and distance to the next coordinate.

there are certainly other basic ways to build a random walk app that will take a different approach. The suggestion here is based on what I think you indicated the app should do. Does it use a map? Does it use straight line distances or calculated distances using mapped paths or roads..AI has tools for determining both.

"I'm new to AI and am looking for a little guidance on how to access these variables  last route points coordinates in tinydb, and first ones in the new route." First you need to learn to use the TinyDB. Are different routes stored in separate Tags or are all your coordinates stored in the TinyDB as a List?
This is not Python, here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .
Also look here App inventor español. Offline. Tutorial. Ejemplos. Instalación. Códigos. Juegos. Curso gratis de App inventor. and here Tutorial Index  Imagnity for more tutorials.
Here's where I get the data for the points that make the path on the map:
I am using openrouteservice.org. Printing these points out to a temporary textbox I notice that openrouteservice delivers the points coordinates as a list of coordinate pairs. Here are the blocks that retrieve the points:
First I hide the keyboard, place a marker at the current location, and pan the view to centre on that marker.
I then place a destination marker at a random position on a circle whose radius is the distance chosen for the walk. openrouteservice.org then returns the route points from the origin (current location) to the random destination. This comes as the list of coordinates that I mentioned and would like to access by index. They get passed to the linestring object to display the route on the map.
I've started looking at lists and suspect that's where the answer lies. I just can't figure how to break up the coordinates from openrouteservice.org into separate coordinate elements to place, one by one, into the list. Or if I even have to do that if I have the facility to access the openrouteservice.org list. In python speak the list is a list of tuples and looks like this:
((lat1 lon1) (lat2 lon2) ... (lat_n lon_n))
What I'm thinking to do is compare the last pair of coordinates stored in tinydb with the first pair of coordinates in the newly retrieved list from openrouteservice.org. If they're the same, then I'm backtracking and need to generate another destination.
Thank you for your interest and taking the time to respond. It's very late where I am and I have replied in some haste. Let me know if there is anything I can do to make it clear. I have the app working fine and I'm having huge fun field testing it around town, wandering down alleys and backstreets I never knew existed. But remember I've only been using app inventor for a couple of days. I'll check out the links you provided tomorrow.
Just a note to say I have discovered the solution in
...duh. I feel kind of stupid now, but it does exactly what I was looking for and works perfectly. Thanks again for your time and attention
Glad the advice helped @d8sconz Thank you for sharing your code.
I experimented with your algorithm. I get some strange results. Perhaps I miscoded?
(these are draggable Blocks)
Were did you find the algorithm?
I plotted a circle with a 1000 m radius on the map. I used the algorithm you shared to locate Markers with the following results.
The plot indicates that the algorithm (or my interpretation of it) is not precise. All the markers should be on the circle.
I got the algorithm down a google/stackoverflow worm hole that began (I think) from here.
Tbh your result mirrors my own. I don't fully understand the math and the results I'm getting are good enough for the toy application I'm making. On one of the threads someone had implemented a python version of the algorithm which I tested and which neatly placed all points on the circumference of the circle (after I had removed the random circumference element  OP wanted points randomly within the circle, not on the circumference). But this was in matplotlib, not gis locations. What I get from the threads is that, given that the earth is not a perfect sphere, these types of calculations are very difficult to get right, especially at the tiny scale we are working on here. There could also, of course, be something fundamentally wrong with my implementation of the algorithm. For now, I get interesting random routes for my afternoon walks that are taking me to all sorts of interesting places.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.