Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager geo-fencing/startMonitoringForRegion: vs. startMonitoringForSignificantLocationChanges: vs. 10-minute startUpdating calls

Tags:

I am trying to set up an app that will be able to check people's locations in the background, see if they are at a given location, and send a ping to a server if they are. We do not want to drain the energy of our users, so we are attempting to figure out the best solution.

I've done substantial reading and I have not found very much information on these methods. I'll go through the pros and cons as I understand them right now

startMonitoringForSignificantChanges

Description: Based off of wi-fi and cell tower changes the system wakes up the app.

Docs:

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

Pros:

  • Most battery efficient

Cons:

  • Dependent on wi-fi/cell tower changes
  • Can only assume that this will be called every 200m to 2km (if not more in certain areas)
  • More on accuracy
  • Thus, inconsistent and imprecise

10-minute start-updating or "n-minute updating":

Description: This basically asks the app for more time, when that extra time is about to expire, it calls [self.locationManager startUpdating], grabs the location and extends the background thread for 10 more minutes.

Pros:

  • Consistent
  • Can be as accurate as you want it to be as consistently as you want it

Cons:

  • Has to do a call every ten minutes or less to keep the app running in the background (ie n can't be greater than 10 for the calls)

Questions: What effect does this have on the battery? Does waking up the GPS and shutting it off hurt the battery more? I couldn't imagine running a brief location check in the background would drain the battery that much... but then again, I don't know what goes into powering up the GPS and getting a usable signal.

startMonitoringForRegion (geo-fencing):

Simply put, your app gets woken up when you enter into a pre-defined region. This is the oddball of them, it is more recent and there is less documentation on it. I can't find a good description on how the "system monitors" the boundary crossing. For all I know it is some really smart algorithm, or they are constantly pinging the GPS which would make it less effective than the other methods for doing this.

Pros:

  • Simple implementation
  • Managed by the system so you don't have to invent your own ad hoc geo-fences Only triggers on boundary crossing... no unnecessary data to just throw out in exchange for a battery hit
  • Thus, should be the best for this sort of thing, accurate, managed by the system

Cons:

  • People question its effectiveness
  • Huge conflicts on whether or not it is good for battery life or if it drains battery life terribly.
  • How is the system monitoring this!?
  • Basically, indeterminate behavior.

I guess my question boils down to how does startMonitoringForRegion: compare to these other methods of testing user location in the background when it comes to battery life, consistency, and precision. Has anyone thoroughly tested this? Or used it in their app and gotten at least some feedback? Likely, for my purposes, the trade-off is between geo-fencing and the 10 minute update method. (Also given what Apple has publicly said about iOS7 there will be some background tasks... will this change the calculus for the trade-off between these two methods?) Does anyone have an idea of how these two compare?

Thanks so much! Looking forward to seeing if we can get to the bottom of how to compare these methods.

like image 526
AdamG Avatar asked Aug 15 '13 22:08

AdamG


1 Answers

I've been working on vehicle tracking using GPS for 2 years. Learned a lot the hard way... In my experience startMonitoringForRegion or Geo-fencing depends upon cell change events, didEnter or didExit events doesn't fire up until there is a cell/wifi change event. So it doesn't make any difference w.r.t battery consumption. However it does extra computation which depends on how many regions currently are being monitored. Even Apple's Reminder app doesn't give good results for location based reminders because it uses geo-fencing.

The other approach starting GPS for n minutes after each m-minutes is good option, it should not affect the battery life, if done wisely. What exactly effect the battery is constant GPS activation in high precision mode. Like for instance If you enable GPS with kCLLocationAccuracyBest and distance-filter = 0, you can literally observe battery drainage and soon your device will also start getting hotter.

If I was you, I would go for activating GPS after every 10 minutes for 5 sec with kCLLocationAccuracyBest (or may kCLLocationAccuracyNearestTenMeters to use less battery, if accuracy is not that much important) and distance-filter = 5 (meters). Battery consumption in this case will be unnoticeable. You can play around with similar settings which can address your specific case and finally find out what is best you.

BTW: iPhone uses AGPS, A-GPS additionally uses network resources to locate and use the satellites in poor signal conditions. So, when you do startUpdatingLocation it will also use nearby cell tower information. see http://en.wikipedia.org/wiki/Assisted_GPS

like image 142
Zee Avatar answered Sep 18 '22 15:09

Zee