Question

I'm writing an Android application that notifies the user when he enters a specific region. For this I used the Geofence API from Android.

I have tried Google's GeofenceDetection sample, and The application does not get notified at all.

I call addGeofences, and receive onAddGeofencesResult notification with statusCode 0, so all seems to be working fine, but when I walk (or drive) in and out of the geofence (with radius 5m or 50m) nothing happens.

I use Nexus4 and Eclipse - both updated to latest versions.

Why don't I get geofence notifications?

Was it helpful?

Solution

I've found that the GeoFencing API never intelligently retrieves locations from the GPS hardware. The GeoFence API will observe the most accurate location available from the OS or if no location is currently 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 behaviour is not documented- thanks Google!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top