iPhone GPS - Battery Draining Extremely Fast ** Please Help **
Hi Gurus,
We are developing an app that has heavy GPS usage and we are unable to optimize the battery life. Even when the device is not moved, there is significant battery drainage which according to the code should not happen.
Here is the code:
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
We want to trigger GPS every 20 minutes (if there is no location change then save battery) OR every 5 minutes if there is location change. According to my developer this cannot be done.
Previously we were using kCLLocationAccuracyBest, which was consuming battery very fast and now we are using kCLLocationAccuracyHundredMeters.
startUpdatingLocation - is to get the GPS coordinates. There is another call startMonitoringSignificantLocationChanges which is to get AGPS coordinates which I believe returns the coordinates whenever cell tower will change, and hence consumes battery really fast.
distanceFilter - The minimum distance (measured in meters) a device must move laterally before an update event is generated. On the basis of distance filter we get the GPS fix from the device and then we send the updated GPS coordinates to the server.
Any help will be greatly appreciated Thank you!
Last edited by kapil403; 12-31-2011 at 12:12 PM.
Reason: layout
We are developing an app that has heavy GPS usage and we are unable to optimize the battery life. Even when the device is not moved, there is significant battery drainage which according to the code should not happen.
Here is the code:
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
We want to trigger GPS every 20 minutes (if there is no location change then save battery) OR every 5 minutes if there is location change. According to my developer this cannot be done.
Previously we were using kCLLocationAccuracyBest, which was consuming battery very fast and now we are using kCLLocationAccuracyHundredMeters.
startUpdatingLocation - is to get the GPS coordinates. There is another call startMonitoringSignificantLocationChanges which is to get AGPS coordinates which I believe returns the coordinates whenever cell tower will change, and hence consumes battery really fast.
distanceFilter - The minimum distance (measured in meters) a device must move laterally before an update event is generated. On the basis of distance filter we get the GPS fix from the device and then we send the updated GPS coordinates to the server.
Any help will be greatly appreciated Thank you!
If you leave the GPS actively updating your location, you will suck down the battery rapidly. Using a lower accuracy helps a little bit, but only a little bit.
What we did for some of our development was to ask for location updates at regular intervals. We start updating the location, wait for a signal that has a current timestamp and acceptable accuracy, and then stop updating again for a period. The longer the interval while you are NOT updating locations, the better your battery life. It takes the GPS a fairly long time to get accurate readings after you start updating again though (15 to 30 seconds) so your update interval needs to be pretty long in order to get a good benefit from it.
We haven't used it, but supposedly the significant location changes option is an excellent way to be notified of user movements with very low power use.
To quote Apple's docs:
Quote:
This method indicates whether the device is able to report updates based on significant location changes only. (Significant location change monitoring primarily involves detecting changes in the cell tower currently associated with the device.) This capability provides tremendous power savings for applications that want to track a user’s approximate location and do not need highly accurate position information.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
We haven't used it, but supposedly the significant location changes option is an excellent way to be notified of user movements with very low power use.
I used significant location changes in the last app I did. It does provide a low power option but the updates are not particularly reliable (in terms of frequency, not actual position.). If you want to use region coding it only works for iPhone 4/4s _Hardware_ - it's not only a feature of the OS but also of the hardware.
If you are Ok with just getting a position every now and then then it's a good deal - but you will only get a position when you have traveled a significant distance. Depending on where you are testing this it could be several kilometers between updates.