0

I've been developing a tracking app for Android in which I need to track a person using GPS fixes very often (10 seconds interval tops).

Turns out that after couple of minutes my phone warned a battery-draining app - my app.

Although I know GPS fixes uses lots of battery, how is it possible to use Google Maps tracking for over an hour without drain-battery and still get instant GPS changes fix?

Thanks a lot.

Here's an idea of what i'm doing:

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, locationListener);

That's pretty much it of battery-draining in my whole code.

ricardofagodoy
  • 146
  • 1
  • 10

2 Answers2

0

You have something else going on. GPS doesn't drain that much battery. You can have it going all day in the background and it will take up less than the phone's radio. What drains the phone is when you use GPS and keep the screen on. Or when you constantly send the location to a server- keeping the networking radios on all the time will kill a lot of battery. But GPS itself is fairly cheap.

Also, tracking everyone every 10s is pointless. GPS doesn't even update that fast.

Beyond that posting your code could help, we could see if you were doing something stupid.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Tracking everyone every 10s is not pointless. It is very common to so. Even tracking at 1Hz is realistic for some use cases in the consumer area – j3App Jun 05 '18 at 10:38
  • @j3App No, it is utterly pointless. Even if you had a usecase that required that level of accuracy (you don't) a human at walking speed won't even get out of the accuracy range of the initial reading in 10s. Its common because of ignorance, not because its a good idea. – Gabe Sechan Jun 05 '18 at 13:23
  • I do not think anybody mentioned walking speed. At e.g. 100km/h, a person moves 28 meters every second, that is 280m in 10 seconds. And if you only want to consider walking, you can easily walk 2m/s (roughtly 7km/h). Again this would be 20m in 10 seconds, and GPS is most more accurate than that. – j3App Jun 05 '18 at 13:42
  • @j3App If you're talking about that speed you're driving and need even less accuracy. Cars just don't change course and direction enough to make 10s worthwhile. Assume course and heading and check less often. – Gabe Sechan Jun 05 '18 at 13:45
  • whether worthwile or not depends on what you want to achieve. There are tons of usecase that benefit from 10 sec or less sample rate. Now let's move on – j3App Jun 05 '18 at 13:48
  • @j3App We can move on, but you're just wrong about that. There may be some, but they're a tiny percentage of the use of GPS. If you're using a 10s refresh rate you're almost certainly wrong. – Gabe Sechan Jun 05 '18 at 13:49
-1

"how is it possible to use Google Maps tracking for over an hour without drain-battery and still get instant GPS changes fix"

First off, when I use Google Maps turn-by-turn directions, my phone turns into a little heater. The %battery drops like a rock.

Here are some suggestions:

  1. CPU in a active (C0) state is the biggest energy hog. The best way to save energy is to keep the CPU inactive long enough for it to drop into a low energy usage state (>C0).
  2. The longer you position update period, the less energy the CPU and other peripherals use. This is because, once again, you're allow them to drop into energy conservation states.
  3. Think about extrapolation. I'm sure Google Maps and other such software does this. So if you update every 30 seconds, you can extrapolate the position from the previous points. If you really want to be clever, you can look at your position history to have a variable update.
  4. As Gabe said, it sounds like you have an error in your code that keeps the CPU and/or WiFi-GPS active all the time. There are some Android APIs that will leave peripherals on, and others that do the same thing that don't. And, of course, polling should always be avoided.

Here's something I answered a while back that discusses energy usage.

Good luck.

Community
  • 1
  • 1
Taylor Kidd
  • 1,463
  • 1
  • 9
  • 11
  • #2 is correct. If you update every 10ms, the processor will not drop into the higher C states due to trying to minimize latency. Devices also have power D-states. If instead you use 1 sec, the processor can drop into lower more efficient C-states. See my [performance article](https://software.intel.com/en-us/articles/power-management-states-p-states-c-states-and-package-c-states). #3: I can't claim direct knowledge about extrapolation but can't believe they don't do linear extrapolation for a well-designed application. – Taylor Kidd Aug 29 '16 at 18:57