3

I'm building an app for mobile which needs to monitor the distance between the user's location and multiple location markers at regular intervals. From what I have read here and on other sites, I have three options:

1) use the distanceTo and distanceBetween functions to calculate the distance between the user's location and each location marker
2) use proximity alerts associated with each marker location
3) use geofences associated with each marker location as per Creating and Monitoring Geofences

Which approach is the best to use in light of (a) ease of implementation, (b) battery drain, and (c) gps / location accuracy? Given that I am designing predominantly for mobile, I am assuming that wifi will not always be available.

1 Answers1

3

An important note on the Google Play GeoFencing API. I've found that the GeoFencing never intelligently retrieves locations from the GPS hardware. The GeoFence API will observe the most accurate location available from the OS or if no recent location reading is available, it will cause a location to be calculated from Wifi / Cellular. (which sucks because cellular is wildly inaccurate and wifi is often unavailable)

So to get at all responsive or accurate results out of the Geofencing API you have to set up your Geofences and then poll the GPS hardware on an interval, not even doing anything with the result received, so that under the surface you are providing worthwhile data to the OS.

I can't speak specifically to the behaviour of LocationManager.addProximityAlert but I doubt it behaves any differently. You could really use either and the results and performance will likely be identical because the heavy lifting is done by waking up the GPS manually.

As for how to implement your current distance to your fences, none of the proximity APIs have an interface to determine this for you. In the situation I describe above when the GPS poll occurs, instead of doing nothing with the result, I'd use it with distanceBetween to update the distance between myself and the points I've set my GeoFences at.

stealthwang
  • 915
  • 6
  • 8
  • Many thanks for the response stealthwang, it seems like a lot of work to get the geofencing to work properly. Do you think polling the GPS at regular intervals in the way you described would be a significant drain on the battery? – ConfusedByTheMetricSystem May 09 '14 at 11:59
  • No I haven't found it to be in my testing, though power consumption was not widely profiled in testing as my apps target device will typically be installed in a vehicle. – stealthwang May 31 '14 at 01:58