How to implement "un-dwell" in android geofences?
Asked Answered
V

4

15

I have a problem understanding Androids geofences.

Actual Problem: I used Enter+Exit events from googles geofence-api, but on many devices the signal is so inaccurate that it jumps in and out a fence (jumps are greater than radius 400m often).

Planned Solution: So I want to use Dwell to "smooth" this. If the location keeps inside a fence for a minute, dwell happens. So far so good. But how do I detect the leave of a fence? When I use Exit, several Exit can happen due to those signaljumps. What I need is a kind of "undwell", when I leave the geofence for more than a minute.

I want to avoid reimplementing the whole Geofence with custom logic that registers on fast repeated geo-locations and filter out small outliers.

Question: Is there something in the geofence-api to achieve an "undwell"? Or is there a best practice how to check if an Exit is a real exit?

Valenza answered 26/1, 2016 at 13:17 Comment(4)
hey how'd this come along for you @Jens?Emmerich
since there are many votes on my question but nearly none on the answers/suggestions i think there doesn't exist something out-of-the-box or best practice. What I'm doing currently, is to play around with 2 approaches: One is, to implement 'undwell', that means: on-EXIT I start a periodical location update and recieve 3 location updates. If all 3 are still outside, I accept it as a real exit, then, remove the listener. The second experiment is to do fencing all myself with locationUpdates and do smoothing also myself (using 3, or even 5 locations, ignoring outliers).Valenza
Just wondering if you ever managed to find a solution to this problem as I am currently stuck with this issue also and would really appreciate some help.Aleece
Yea I stick with the suggestion of my last comment over yours. I did it myself with a plain location update after EXIT event and decide myself if i'm really long enough outside but you need also to be aware of all other implications like it could happen that the user enters the fence quickly again etc.Valenza
G
1
    public long lastEnterTime = 0;

    public void initTimer(){
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if(lastEnterTime!=0 && System.currentTimeMillis() > lastEnterTime + 1000*60){
                    lastEnterTime = System.currentTimeMillis();
                    onRealEnter();
                }
            }
        },0,1000);
    }

    public void onRealEnter(){

    }
    public void onEnter(){
        lastEnterTime = System.currentTimeMillis();
    }

    public void onExit(){
        lastEnterTime = 0;
    }
Grenadier answered 30/1, 2016 at 4:43 Comment(1)
This answer is more like an alternative implementation for "dwell" rather than my wanted "undwell". Also a 1 second time seems to be a worse than other workarounds (like just starting a 1-time firing timer to recheck if the user really left the fence). :(Valenza
C
1

In Google Geofences, Enter event triggers every time you enter a geofence, Exit event triggers every time you cross the boundry of the Geofence. Also Dwell event triggers when you stay inside a geofence for a specified interval of time.

In your case, if you keep jumping In and Out of a geofence in less than one minute, Dwell will never happen.

If you enter a geofence, Enter event triggers, and then you stay inside for one minute or more, Dwell will happen, and after the Dwell happens, if you notice any Exit event, you can use that Exit event as a real Exit.

Note: You can also increase the radius of Geofence.

I hope my answer will be clear to you. :)

Concise answered 1/2, 2016 at 3:16 Comment(3)
That wont work since you get an Exit immediatly onExit, not like dwell. So if you use dwell+exit you come up with something like: (ignored enter)->dwell->exit->(ignored enter)->exit->(ignored enter)->exit->(ignored enter)->dwell->exitValenza
In my case, i have never notice any jumps in and out of a fence. Try to check you LocationServices API. How are you getting location? Try to get More accurate location. It may fix the issue.Concise
I've already created a testversion, were i have added requestLocationUpdates with high accuracy and interval 30s, additional to the Geofences. It does increase the accuracy but also brings even more of those "jumps". I've recieved several users geologs where they haven't moved the phone and i have added those 30s values on a map. You can see like 30 values inside fence, then 1 value 500m away and then the next 30 values again inside. And that happens on all vendors. So the only workaround I found so far is to request a pos every few seconds and smooth the signal. That kills battery.Valenza
K
1

This is just an idea, but for every area you could register two geofences with different radius. Register to listen for DWELL for the geofence with the smaller radius, and for EXIT for the other one.

Kronfeld answered 3/2, 2016 at 10:51 Comment(1)
The EXIT-Event is still the issue, because it triggers immediatly. So this would not solve the "jumping location" issue. But what could work based on that idea, would be an outer great geofence also listening to DWELL. If the outer DWELL is fired while the inner is in EXIT-state, this implicitly means, that you are outside. There are still 2 issues, though. One is, that the timing could be bad and you are just jumping inside of the smaller fence when DWELLING the outer fence. The other is, that you don't know the update-rate so the outer fence should be as huge as a city or country.Valenza
A
0

You can use setNotificationResponsiveness to set a longer notification time, so you won't get an exit event unless it stays really outside of the fence for that amount of time, so jumps won't trigger exit events if they happen within this time

Amylopsin answered 25/9, 2017 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.