I am having some trouble figuring out how to properly track the location of our application's users continuously throughout the day.
It needs to
- Get the user's location either every x minutes, or after they travel so far.
- Submit the collected points every 15 minutes.
- Work in the foreground and the background.
- Not destroy battery life, as I need it to get locations for 8 hours.
The users should be stationary for most of the time, with a car ride every 45 minutes or so that I need to get the route of. The application may or may not be in the foreground at all throughout the day.
I have used both the Xamarin Mobile component and a custom written tracker based upon this walkthrough written in Xamarin's backgrounding guide.
Our tracking, using that code, runs fine in the foreground, and I discovered I was missing the option to turn off the
PausesLocationUpdatesAutomatically property. I assume that when I use that, the application will continue to run in the background indefinitely.
The application did not resume from Pausing ever when we forgot to turn that property to false. The user had to open the application to resume tracking.
Our issue comes from two things: first, we need to submit the list of coordinates taken to our servers every 15 minutes or so. I have the Http queries to do this, they work in the foreground, and as I use the
BeginBackgroundTask logic described in the backgrounding tutorials, I assume they will keep running for the lifetime of the location tracking running?
Second: as might be expected, tracking location all day is very consuming for the battery life. I have read Apple's recommendations on using Significant Changes or Region Monitoring approaches, but significant changes are not accurate enough for our needs.
If I use region monitoring and allow our location manager to pause, I cannot figure out how to restart the manager after I get the notification I left the region.
Are there any suggestions to change any parts of this process to improve battery life and reliability? To reiterate, I do not need you to code me a solution, just help point to the right way of getting the job done.