How to make Geo Fencing alert more accurate in Android

I also had problems with the geofence system jumping in and out of my geofences and then i read this (Quote from official docs):

There is no reliable network connectivity inside your geofence. If there is no reliable data connection, alerts might not be generated. This is because the geofence service depends on the network location provider which in turn requires a data connection.

From the official geofence documentation


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.

This is probably at the core of why your results are inaccurate. The geofence exit won't trigger until the OS is sure you're 100% outside the fence - so if a location reading has an accuracy of 500 meters (not improbable when using cell geolocation) and your fence has a radius of 50m you'd have to be at least 550m from your fence point to produce an exit event.

TLDR; Poll the GPS hardware on an interval without doing anything with the result and you'll start getting more accurate geofences.


I summarized the best practices from several StackOverflow threads regarding Geofencing in Android in a sample project on Github called Geofencer. This can be used to as a reference to implement GeoFencing into your application. It also allows to switch to a 3rd party GeoFencing implementation on the fly. I hope this is helpful for some of you!