views:

86

answers:

2

Hello all,

I'm trying to limit my program to take location updates every 10 seconds instead of constant updates in order to reduce battery drain. This works fine when i'm debugging indoors and the signal is weak (i.e. the GPS icon flashes), but if the phone gets a proper fix (i.e. the GPS icon is static) the update interval increases to roughly a second.

I know that the code mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateInterval*1000, 0, this); will not force the GPS to take updates exactly at the given interval, but in my opinion it shouldn't depend on the strength of the signal and fluctuate that much.

Any ideas?

UPDATE: see comment

A: 

Maybe it works slower because you are debugging, but not because your signal is weak! Try to make tests with disconnected debugger indoors...

cement
Good idea, but i'm on a laptop, so debugging everywhere :) Tried also a build with no debugger and aLogCat app, same thing happened.
onik
+1  A: 

I suspect that the GPS radio works in a manner where either it's connected to GPS satellites or it's not. When it's connected, the Android SDK sends you updates as frequently as they're available from the GPS hardware. When it doesn't have a full GPS connection it falls back to sending AGPS updates according to what you've requested.

If you only want updates every 10 seconds, you should save the last received Location's time value in your listener, and when you receive a new Location check its time against the old value; ignore it if it's too frequent (or do something smarter like checking the accuracy and replacing the old value, etc).

Alex Pretzlav
Your suspicion is correct. On 2.1, the system itself filtered the GPS locations according to the update interval and didn't pass the extras to the LocationManager, but I still could see them in the logcat. On 2.2, all of the GPS fixes are passed to LocationManager (apparently). However, since using updateInterval doesn't save any battery (or so it seems), I'll test your method and report back.
onik
Yep, had to use a timer-based solution to switch GPS location receiving on/off since there are no better options.
onik