Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone GPS - Battery Draining Extremely Fast

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 that, according to the code, should not happen.

Here is the code:

locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];

Ideally 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!

like image 726
KB403 Avatar asked Oct 23 '22 13:10

KB403


1 Answers

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.

That's exactly what it does, but you're jumping to conclusions about the power required for that. The GPS receiver and WiFi transceiver can be used to help determine location, but they're extra devices that have to be powered to be useful. But mobile phones like the iPhone need to keep in touch with the nearest cell tower anyway in order to receive phone calls, so using cell towers as a source of location information should be very efficient with respect to power. Here's what the CLLocationManager reference page says about -startMonitoringSignificantLocationChanges:

This interface delivers new events only when it detects changes to the device’s associated cell towers, resulting in less frequent updates and significantly lower power usage.

It also describes the service as providing "tremendous power savings," so it seems the right tool for the job you describe. Of course, if you're also using the standard location updating mechanism at the same time you won't see that power savings, so make sure you're not using both.

Ideally 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

It sounds like there's some sort of misunderstanding here. You can certainly fire up the GPS every 20 minutes to get a fix if that's what you want, although you can't do that from the background. The significant location change service will notify your app even if it's running in the background, so perhaps your developer is talking about background updates.

like image 199
Caleb Avatar answered Nov 15 '22 04:11

Caleb