How to make Geo Fencing alert more accurate in Android

耗尽温柔 提交于 2019-11-28 05:34:19

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!

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

Android's native geofencing is shockingly inaccurate and battery intensive. I suggest you use a third-party tool like Bluedot's Point SDK (accurate to 10m/30 feet) or Gimbal's SDK (accurate to 50m/165 feet), both of which are much more reliable with less battery drain.

Full disclosure: I work for Bluedot.

If che device is not connected to internet google play services (like geofence or activityrecognition) don't work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!