Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement "un-dwell" in android geofences?

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?

like image 670
Jens Avatar asked Jan 26 '16 13:01

Jens


3 Answers

    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;
    }
like image 152
tiny sunlight Avatar answered Nov 07 '22 02:11

tiny sunlight


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. :)

like image 1
Muhammad Ibrahim Avatar answered Nov 07 '22 01:11

Muhammad Ibrahim


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.

like image 1
Mimmo Grottoli Avatar answered Nov 07 '22 02:11

Mimmo Grottoli