2

I am building an android app(Geofencing) wherein I need to check if the user's location is within a given polygon. The application can tolerate some delays in detection but has to be battery efficient. What I am currently doing is as follows - Set up a callback that is fired when the user's location changes by say 50 meters(variable). In the callback, check if the current location is within the polygon or not using the point-in-polygon algorithm, and update a shared preference accordingly.

Now, I was trying to optimize it by using Google's Geofence API, but it only works for circular geofences. Here's what I thought -

  1. Compute the smallest circle that can cover the entire polygon
  2. Use Google's Geofence API to set up a callback which will be triggered when the user enters and exits the circle
  3. When the user enters the circle, set up a callback like the current implementation(i.e. get updates every 50 meters and store the on/off-campus shared preference)
  4. When the user exits the circle, remove the callback.

So, in this case I would avoid taking updates when the user is not in the circle at all. But, the question is, how much better is google's Geofence API as compared to the fused location provider?

Jeetendra Gan
  • 165
  • 13

1 Answers1

2

Although I don’t have inside knowledge about the Geofence API, I very much believe it’s based on the fused location provider (FLP).

When a Geofence is set and the device registers motion, locations are requested by FLP and checked against the Geofence.

Some evidence for this mechanism can be found in Android bugreports (https://developer.android.com/topic/performance/power/setup-battery-historian). For example, I found the following line when using a geofence (Galaxy S9, Android 10):

Request[PRIORITY_BALANCED_POWER_ACCURACY requested=1800000ms fastest=5000ms] tag=geofencing moduleId=com.google.android.gms.location.geofencing hideAppOps=true clients=[my_app] forceCoarseLocation=false exemptFromBackgroundThrottle

Essentially, it means locations are requested every 30 mins at balanced accuracy (i.e. wifi precision) for a geofence set by my app. This is the longest possible delay for a geofence trigger. And locations triggered by other sources are passively located at minimum interval of 5s.

Using your own locations requests combined with a point-in-polygon check might consume more battery if the locations requests are not timed according to motion.