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 -
- Compute the smallest circle that can cover the entire polygon
- Use Google's Geofence API to set up a callback which will be triggered when the user enters and exits the circle
- 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)
- 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?