Do I need to request location updates when using Fused location Geofences?
Asked Answered
E

1

9

I have successfully implemented location geofencing using the Android Developers documentation.

The problem I am having is that the geofence events are not always reliable. Sometimes they trigger as soon as I'm at the location, sometimes they take a few minutes (even with a large radius value), sometimes they don't fire at all.

I have also noticed that even though I have enabled GPS, the app is not using the GPS sensor to get my location.

Is this because without requesting updates the Fused Location provider is in a "passive" mode and relying on other apps' requests? Do I need to implement location requests as well as geofencing?

Enure answered 12/1, 2014 at 17:33 Comment(1)
Did you find the solution to this?Poop
T
3

Not sure if it answers your question completely, but I am working on app that implements geofencing and also location requests and these are my observations:

When app is active and I am receiving location updates (the location is known), geofencing behaves accurately - I get Intents almost instantly.

When app is inactive, I observe same behaviour - sometimes Intents are instant, sometimes it takes a while and sometimes it takes just too long. Of course, when there is some other app, f.e. Google Maps, requesting location, Intents are again, almost instant. But when there is no need for acurate location, it usually takes a while. Total nightmare are people with wifi/mobile data turned off and moving between buildings. Because inside, there is no GPS, and they spend outside so little time, that the phone usually does not wake up...

So, I would say this is actually expected behaviour. (Otherwise battery life would be horrible)

Trexler answered 12/1, 2014 at 17:57 Comment(4)
Thanks for your reply. It sounds to me that more frequent location requests may be a solution to this. According to Google's IO 13 presentation, a balanced fused location provider drains ~0.6% of the battery per hour and the typical request interval is 20 seconds, so it might be a good trade-off between accuracy and battery drain.Enure
Slightly off-topic but have you had any success getting geofences to work outside with only GPS (no cell)? I get the trigger if some other app is requesting the location like you said (e.g. Maps) but not otherwise.Enure
I am not sure it is even possible - whenever I turn of wifi and cell location on my phone (Device only mode in KitKat) I get error: Goefences not avaliable. So I would say we can't do anything about that now :/Trexler
I've found exactly the same problem, and for a few days I've been struggling to find a good trade-off. Relying solely on the automatic location updates on the phone seems to work fine if you are settled for a period of time in a location, but often if you are driving you will drive through a location completely without triggering the fence, even with GPS switched on. If Google Maps is on however, the fences are triggered instantly. I think the solution is to implement your own service which polls at 20 second intervals and accept the battery trade off.Proximal

© 2022 - 2024 — McMap. All rights reserved.