I really hope to find some help here.
I need to track at all time, if my users are within a radius of 100m of a certain geolocation (let’s call it “Home Location”. I need to know at all time which user is at his home location, and who is not (even when the app is running in background or is closed/ terminated).
I thought to realize this, using the Ionic Native Background-Geolocation plugin and the cordova-plugin-background-geolocation. My plan was, to check the users geolocation every 5 minutes and compare it to the home.
Case 1) If the distance between the two locations is < 100m I know the user is “at home”. I would then update the user node in my database (Firebase) to mark the user as
isAtHome: true and add a current timestamp.
Case 2) If the user is not within 100m of his home location I would mark him as
isAtHome: false and add a current timestamp.
I need to update my database even in case the user didn’t move, because I need to know that I received a current signal. Otherwise I don’t know if he didn’t move or turned off his smartphone, for example.
If I want to know, who of my users is at his home location, I would check the
isAtHome-attributes and if they are set to
true, I would check the timestamp to be sure that I have up-to-date data and the data was written within the last 15 minutes.
I tried many different things, but I’m not sure how to realize this with the Cordova Background Geolocation Plugin and if it’s even possible.
My question is:
Is it possible to check the users geolocation every 5 minutes (even in background / terminated state) and call a function that updates my firebase DB accordingly? As described, I need to receive the location even if the user didn’t move within the last 5 minutes.
If it isn’t possible: Does anybody have an idea, of how to approach the requirements on another way?
Thank you very much for your help!