Tracking Highly Accurate Location in Android — Vol.4, Battery Consumption

콘텐츠

Taka MizutoriHow to track user’s location with high accuracy (iOS / iPhone)

In the last three sessions, we have made a very accurate location tracking app. In this blog post I use this app and examine the battery consumption.

I’ve been using my app while commuting my office by bike everyday and checked the battery consumption.

My commuting path is around 6 kilometers, and I used Nexus 6p and Nexus 6.

Sorry for Japanese titles for the table.

From left side, the values are

  • total time of logging in seconds
  • distance of logging in kilometers
  • number of locations logged
  • battery at the start of the run
  • the battery at the end of the run
  • battery consumption in percentages.

And two right most columns are

  • predicted battery consumption if I keep running for 42 km at the same pace
  • predicted battery consumption if I keep running for 5 hours at the same pace.

The result shows my app can keep running logs while full marathon. (5 hours are average time of wemen in a full marathon.)

If you do web access while logging, which add much more extra battery consumption, so measure your case and assume above amount is rough consumption from GPS logging.

The sample app has below code which measures and log battery consumption values to CSV file. So utilize this feature for your case.

registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTIONBATTERYCHANGED));

CSV file is stored under the path below. Use adb shell to check the path, and use adb pull to get the file.

/sdcard/Android/data/com.goldrushcomputing.androidlocationstarterkit/files

Way to save battery

If you need to save battery further, there are two ways.

  1. Dynamically change criteria according to the current battery level

2. Change Minimum Distance and Minimum Time (if you do heavy processing each time the app obtains new location such as uploading to the server. )

Dynamically change criteria

Check battery level periodically, and downgrade Accuracy and PowerRequirement to File or High in the Criteria object to decrease battery consumption.

Change Minimum Distance and Minimum Time

Increase Minimum Distance and Minimum Time to reduce the frequency of onLocationChanged calls.

Minimum Distance and Minimum Time doesn’t change the power usage of the GPS chip itself. It only affects the frequency of onLocationChanged callback at app level layer. So if you don’t have any big task in onLocationChanged, changing Minimum Distance and Minimum Time doesn’t improve battery consumption.

Below is the battery consumption with minimum distance of 1 meter and 5 meters with my sample app. There is no difference between these two since my sample apple doesn’t do any heavy processing in onLocationChanged.

Remember the GPS chip’s power consumption is affected by Criteria, but no by Minimum Distance and Time.

Ok, it’s all set. I’ve been explaining how to make good location tracking engine in four sessions of the blog until here.
Try all the filters, tune thresholds, and find the best settings for your app.

요약하다
The article discusses the author's experience with a location tracking app, focusing on battery consumption. The author tested the app's battery usage during a 6-kilometer bike commute using Nexus 6p and Nexus 6. The results showed the app could run for a full marathon duration without draining the battery. The article provides tips to save battery, such as dynamically adjusting criteria based on battery level and changing Minimum Distance and Time settings. It explains that changing these settings affects the frequency of location updates but not the GPS chip's power consumption. The article also includes code snippets for measuring and logging battery consumption values to a CSV file. It concludes by encouraging readers to experiment with different settings to optimize their location tracking app's performance.