Lolo
Lolo

Reputation: 4159

How to walk the line between location accuracy and power efficiency?

I am working on an app that requires to work in foreground and background and send location data. I haven't written code yet and just familiarized myself with how CoreLocation works to determine which approach to follow. From the reading I did so far, I gather that:

  1. With startMonitoringSignificantLocationChanges

    • the GPS is never activated
    • it only calls didUpdateLocations (or didUpdateToLocation for ios<6) when a change of radio tower is detected
    • the desiredAccuracy and distanceFilter properties are both ignored
  2. With startUpdatingLocation

    • the battery drain is higher
    • didUpdateLocations is called whenever some hardware from the phone has some data to provide. And because there are multiple hardware components that can be used for location (GPS, radio, wifi), there is no guarantee when or how often didUpdateLocations is called, or whether a new reading will be more accurate than the previous one even
    • the first number(s) are usually bad because they do not rely on the GPS
    • there is no sure way of knowing whether we have the best location we will ever get: it is just a matter of picking among all locations received the one with the best accuracy in the given time window available

I don't see however much discussion or documentation about any intermediate route. What if I want to be power-conscious but get reasonably accurate data when a user has moved significantly? It seems that a possible compromise approach is to:

As far as I know, this approach will work the same in foreground and background and will provide some compromise between the two standard approaches supported by Apple.

Questions:
- Is my understanding correct and my "compromise" approach sound?
- Has anyone used that approach successfully?
- What are the caveats to look for with that approach?
- Is there a better compromise approach out there?

PS: I imagine that I could later refine the approach to take into account the estimated travel speed so that I don't constantly use the GPS when the person is traveling.

Upvotes: 2

Views: 393

Answers (1)

futurevilla216
futurevilla216

Reputation: 992

There are various ways to go about this problem, and it ranges from how complex you want this battery-conscious code to get. The simplest solution is obviously just always using the GPS, however you can get very complicated very fast, such as taking samples every x amount of time, find the most accurate, predict where the user will be in the time leading up to your next sample using the previous samples, etc.

  • The idea of a compromise is fine, however you need to factor in how much you want the users to use your app, how long it will be running for, and how accurate you need the data to be. In the end, it will come down to some trial and error in figuring out what the best combination of GPS and rough data is. You should know that the significant changes don't occur often, but obviously that's relative. If your app depends on users driving in a car at 60mph, then it might not take so long, but if its somebody walking around, then it can take much, much longer to trigger a significant change (if ever).
  • I personally have not used this approach before, but all apps that I've done with CoreLocation require very accurate location data for a short period of time.
  • The caveats to this approach is that it will take lots of trial and error, and may reduce performance of your app. Before you start coding this, you should figure out if your time making this work will pay off in the end. In addition, if you do decide to figure out where the user is traveling based on the samples, you will need to figure out if that actually saves battery - calculations like that could be pretty expensive battery-wise.
  • Honestly, CoreLocation isn't THAT big of a battery hog, and Apple is constantly improving it's energy use. For example, look at Moves for iOS. As a user of it, I can say that the battery effect is almost none, and it's always using my location 24/7.

If I'm not mistaken, Instruments allow you to monitor battery usage, so you can use that if you do decide to do a compromise to aid in your trial and error.

Hope this helped!

Upvotes: 0

Related Questions