Need help to figure it out the timer and Geo-Location function:

Hi, fellow Thunkers,

I have been building this App to solve a major issue to track users with Alzheimer’s.

As a tester, I have built a 3 screen App. They are:

Screen One: Sign-in screen connected with Signin_Firebase. Every time the user signs in, a location is sent through the realtime DB function to add to the database under their UserID. Also attached the function for the timer on this screen but the primary use is in screen 2. I was not able to get the UserID reference in screen 2.

Screen Two: Just with a label and a button to go to the next screen for signing out. The function of the timer is to be set here so that at an interval of every 10-15 minutes it sends another location ping to the database under the userID. I have even set the Loop to True. So far it is sending the location coords to the DB but not repeating it after the interval.

Am I missing something or is something wrong about the blocks. Any help here would be appreciated.

Thunk You
Abhisar

Isn’t the “location” returned by the location sensor already a list (of the latitude and longitude)?
So if you want to save it, turning it into a list of list is perhaps not indicated…

Also (not too familiar with that specific logic, so may be wrong about it) it seems that “userid” is returned by the firebase sign-in process, but that is a local value that is probably valid only in the overall call SignIn logic block, and be forgotten by the time the Timer1 fires. Saving it in an ‘app’ variable is possible required.

Final point: perhaps not a good idea to show screen captures that include your most frequently visited sites sort-cuts…

1 Like

Hi,

Thanks for your reply.

  1. Yes the location is being returned correctly in a list format with Latt and Long.

  2. For eg. If my email is the userId, it is being correctly stored with location on the DB. In screen 2 however, it’s not saving as the userId but as text “userId”. Any idea on how can I correct it. I am unable to bring the block from screen 1 to screen 2.

  3. Duly noted. I’ll keep it in mind.

Thunk You

1- yes, and that is why you do not need to have that “list” instruction command there. It is ALREADY a list. Having this “list” command there wraps it in another layer of a list that you do not want.

2- that is what I meant. “userId” that is equal to your login is valid ONLY in the block that got it. “userId” is a variable that is defined ONLY in that block. You need to save the value of “userId” into an “app” variable, so that it can be accessed elsewhere. Something like this:

1 Like

Hi,

Thanks, your solution worked perfectly. Even the timer thing is now working fine.

There is just a small glitch to it. That is, every time it is uploading fresh location data, it is overwriting on the previously stored data.

Any idea on how can I make it add new data under for eg: “app myid” + 1 then “app myid” + 2 or create a user branch in Firebase and record data as 1, 2, 3, 4 so on under the tree?

And truly, thanks for whatever you have helped me with so far.

ABhisar

Sorry,

One more issue was that every time I would switch the screen “not kill the App” but to do something else. The location sensor stops working. Any way to fix that so that the App can work in the background?

If you want to add to a database, as opposed to replace previous, you will have either have different keys (i.e. use the key with a suffix, like userid_1, userid_2 etc.) but then you need make a note to what value suffix you are at, so as to know what the next needs to be (you can save the current highest suffix reached in another record, with a key like userid_largest, which you overwrite each time you increment it in order to save another record, or extract the complete existing record (get), save that in a local list, append the new value to that list, and then save back the augmented list as a replacement record using the same key (which will overwrite the previous version).
The downside is that you are extracting a larger and larger record each time, so the data transmission will require more time, and you may end up with delays if your have too much. It is like eating and putting more and more food in your mouth without ever swallowing…

In all cases, you are adding data, so may need some way of cleaning house at some point, and getting rid of old data before they get unmanageably large. That is another thing you have to consider. Large memory does not mean it is infinite; you still can saturate it.

As for running it continuously, I presume this is more something to do with app permission than with the app itself.
Imaging if someone made an app that would run 100% 24/7 behind the scene without your knowledge, juts to drain your battery. Pretty sure Android and Apple would not allow that.
You would have to see the app permission and make it “run always on background” IF it is a valid permission on your device.