View Single Post
Old 11-14-12 | 04:40 AM
  #14  
chrisch's Avatar
chrisch
Senior Member
 
Joined: Feb 2006
Posts: 248
Likes: 0
From: Rotkreuz, Switzerland

Bikes: Trek 520, Gary Fisher Big Sur

Originally Posted by sstorkel
Apple's APIs pretty much make this impossible... They don't want to allow random code to run periodically in the background for fear that some misbehaving app will drain the battery and the user won't be able to figure out which one it is. In addition, this method would require firing up the GPS chip in full-power mode to obtain a position fix. Not as power-intensive as running the chip continuously, but it does use more juice than alternate methods.

chrisch: you may want to consider using the new "geofencing" APIs on CLLocationManager. Specifically: startMonitoringForRegion:desiredAccuracy: or startMonitoringForRegion:. The idea would be to setup a geofence around the user's current location with a radius of, say, 5 miles. When the user goes outside that radius your app delegate gets a notification (via locationManager:didExitRegion:) and you could then record their new position and setup a new geofence around their present position.

Using this technique would allow you to "drop pins" at regular intervals along their route. You could make the size of the geofence configurable: on a local ride you might want pins every mile or two while on a cross-country trip you could get by with 10- or 20-mile intervals.
Thanks for your comments. I believe you're right that it's not possible to run arbitrary code in the background on an iOS device. You can only "subscribe" to updates from given services like position updates. However, you do have control of how often you'd like that update to occur.

The geofencing approach might be an idea, but I wonder how much location polling the OS must do to accurately detect such position changes. I guess it's something that just needs to be tested.

I also appreciate that the iPhone will consume power when detecing a cell tower signal, which may make the significant update approach I originally described useless. This would also have to be tested, but isn't something I can test where I live. Perhaps a hybrid approach is required: Use the significant updates approach when available, but also have a "drop pin" button that uses the standard Location Services (i.e., satellite) to add a point.
chrisch is offline  
Reply