Alex
Alex

Reputation: 1177

About updating the GPS at the background

I am testing some GPS algorithms with the battery life. I just wrote a very simple app using core-location framework and the app update the gps location every second.

I am wondering how can I change the time interval to update my location, like 10s, 1min, etc?

And when my app is at the background it's stop updating the GPS, do you know how to keep it updating at the background?

Upvotes: 0

Views: 243

Answers (2)

AlexWien
AlexWien

Reputation: 28727

I am wondering how can I change the time interval to update my location, like 10s, 1min, etc?

This is not possible and it would not make sense, because the GPS chip needs the same power if it a position is needed once a second or evry 10 seconds. Of course you can ignore positions if you dont like them (if they come to often).

The settings of desiredAccuracy influences the power:

kCLLocationAccuracyBestForNavigation: enabled GPS and Acceleration sensors kCLLocationAccuracyBest: enables GPS but no Acceleration sensors (Cell Tower locating if needed)

kCLLocationAccuracyHundredMeters, kCLLocationAccuracyKilometer, kCLLocationAccuracyKilometer: more likely to use Cell Tower or Wifi locating if available.

That uses less power (more likely) but accuracy is lower.

And when my app is at the background it's stop updating the GPS, do you know how to keep it updating at the background?

If your read Apple's LocationAwarnessGuide ypou find the info, how to set the correct key in Info.plist file.

Since ios 6 there is an additional variant, which should save more power: There is the method: didUpdateLocations (note: plural!):
This will deliver all locations at once such that it ios does not need to keep your application living in background. Once the app enters foreground you will receive all positions at once.

Upvotes: 0

mr.VVoo
mr.VVoo

Reputation: 2270

be aware that iOS usually does not allow background operations in most cases. But at least there are three options to "permanently" determine the location:

  1. As you wrote: determine location all the time when your app is not in background. (1)
  2. determine location all the time - also in background. You need to update your Info.plist and add location as a required background service (required for location tracking, Google Latitiude for instance) (take a look at api)
  3. get location updates only when the location changes significantly.

You are not able to change time intervals or something like that. You only have theses three options - and you can get location information only once when you need them, but that was not the intent of your question.

Upvotes: 2

Related Questions