Storing Old Map Location

My app has a map component that tracks the user (specifically the pet in this case) location by using Long and Lat and showed at the app.


I would like to have another feature where it stores the previous location of the user after pressing the Update Location Button and getting the current location as well

You might use this example that uses a TinyDB to store the location as an example of what you could do with Firebase.
Android11GPSave.aia (4.7 KB)

Adapt the example as required. You could also use a LineString to save all previous locations which requires more complex coding.

Does this example help?

Not really, it doesnt really save the previous location and can only work when the app is closed. I have Firebase on this app so that might work. Is there a code in Firebase that if the data changes, instead of overwriting it, it saves to another branch or data? Are there any ways that I can use?

Closed??? the example only works when the app is open (to work when the app is closed you need to use a Background extension). The example requires manual intervention. It can be coded to work automatically.

Sorry I meant open. Anyways I made a sort of prototype thats based on the example. The app is almost the same but it still isnt working the way I want. Here is the premise:

You open the app and when the screen initializes, it will get the lat and long in Prev Slot, if you had used it before it will show the last lat and long stored before in Prev Slot as well.

If you click Update, it will get new lat and long and show it in the New Slot. Anything lat and long that was previously there will be stored into a TinyDB and put into the Prev Slot, making them Prev lat and Prev long

The app doesnt do this and instead doesnt change. Everytime I open it or press the button, it will give lat and long, but the Prev Slot would be the same as the New Slot. What should I change in the coding here?
SaveGPS.aia (3.7 KB)

What Android version are you using? If you use Android 11 or 12 you may have to set Provider as gps to get the latitude and longitude to update..

It is Android ver 6, but that doesnt really affect my app. the sensor is accurate with giving me the data. My problem is that it doesnt save previous data to my Prev Slot and just gets the data I got when I update it

The idea is like a Ball Sorting Algorithm with two ends of it. One goes in and the other goes out. In this case new data goes in the new and the old goes in the Prev.

  1. Create a list
  2. Store this list to a tag in tinydb
  3. When you get the current lat/lon & data add this as a sub-list to the list
  4. Save the list to the tinydb
  5. Set your Prev Slot data to the last item in the list
  6. When you open the app, set the list from the tinydb, and set the Prev Slot as in 5.

(@SteveJG probably covered this in his earlier example aia :upside_down_face: )

" and set the Prev Slot as in 5." What does this mean?

  1. Set your Prev Slot data to the last item in the list


I'm a bit confused on how to do step 5. Is what I'm doing at this point right?

Something like this (not tested):

When the app is started you load the last set of lat/lon values, when location changed you load the penultimate set (because the new location is the current set. This means after an app restart and the first location change, the prev values will be the same)

Okay it works when I try to apply mine. However whenever I downloadand open it, it says this at first
Screenshot_20221001_055650
IMG_20221001_055738

Its fine whenever I just close the Notification but its a bit worrying. I'll use the same logic on my actual app.

Also for clarification, can you explain how these work?

This happens, because at the beginning there is data in TinyDB...
Just asd an if statement in Screen Initialize after getting the data like this

If not is list empty
Then display the 2 labels

You can find the not block in the Logic drawer and the is list empty block in the List drawer
Taifun

I'm still a bit confused with the select item list to select item list index blocks

See the attached aia project
storelastitem.aia (3.8 KB)

Hopefully you can see how this works

Thanks, This helps alot