Background Geolocation Plugin: Track location and update database every 5 minutes

Hey guys.

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!

Do you have the coordinates of “home”? Then this sounds more like a geofence problem than a continuous tracking problem.

Yes, I do have the coordinates.
However, I don’t want the user to be informed that he crossed the “fence” via push-notification (as it is offered by the geofence-plugin), but I want to execute a function and perform a database-update. As far as I know, this doesn’t work when the app is closed, at least without writing native code…

Good point. Maybe you can combine geofences with background mode then to make this work?

I thought about this, as well. However, using the background-mode plugin has several downsides:

  • works for background mode, but not if app is closed (which is one of my requirements)
  • high battery consumption
  • problems with app store compliance

Hence, I came to the conclusion that this wouldn’t work, as well.

Hey i s this plugin still usable , beacuse now the background mode is not working.