문제

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?

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top