raistdejesus
raistdejesus

Reputation: 109

Performing an action based on location

I'm creating an app wherein I'm need to perform an action when I'm within a certain radius of a location. But I don't want to be continuously polling the location because that'll drain the battery.

I thought about just putting an option for the user to specify how often to query the location. However, I'm concerned that if the user sets it too long, then my app will miss performing the action when it's near the location.

I in one Google IO session that Pay With Square had an auto tab feature, I'm not sure if they're constantly polling the location, have setting for the delay between querying the location or a third option that's efficient without draining the battery.

I would like to ask for suggestions on how to approach this. Thanks in advance.

Upvotes: 2

Views: 1239

Answers (1)

AlexBottoni
AlexBottoni

Reputation: 2307

It looks like your question actually is: "how can I get an accurate position measurement while saving the battery of my device?"

There are mainly two ways to save battery AND have a good positioning:

  1. Do not use GPS (that is a real battery hog)
  2. Set a large interval between poll actions

You can get a quite good positioning (from 40 to 150m radius, that is better than GPS in many cases) using only the wi-fi and phone cell data. Just select "ACCURACY_COARSE", "ACCURACY_LOW" and/or "POWER_LOW" as a provider selection criteria in your code.

See the following links at Google Developer's web site:

And in particular these two:

You can select/set a battery-saving poll interval on the basis of the measured speed of the user. If the user is walking (less than 5 km/hour), you can use a 30 - 60 seconds interval without any risk to miss your alert. If the user is traveling by car (more than 50 km/hour) you will have to set a 1 - 10 second interval. Consider that location space accuracy is usually quite bad (100 m or so) so it does make very little sense to try to "cath" the point with a very high time (speed) accuracy.

Have a look at Google documentation for this, as well.

In any case, Google explicitly suggests to NOT try to save battery using your own code and rely on the getProviders criteria for this.

Upvotes: 1

Related Questions