Geofencing API triggers enter event when already in zone
Asked Answered
P

5

9

I've encountered this problem with the latest Android Geofence API. The usage is exact to the example usage. I set Geofence.GEOFENCE_TRANSITION_ENTER type geofence with 500m radius and expiration is Geofence.NEVER_EXPIRE. This works ok, but if I'm about 10 meters to latitude longitude and I set the geofence, it triggers immediately.

So am I understanding the term Geofence.GEOFENCE_TRANSITION_ENTER wrong here, shouldn't it trigger only when we are outside the zone and enter it, not when we are already in the zone?

Thanks.

Passionate answered 1/7, 2013 at 9:44 Comment(3)
It could be the accuracy and precision of the gps signal:gis.stackexchange.com/questions/8650/…Ballonet
The accuracy is good enough, Location distanceTo at the point showed 200m so it is in the 500m zone.Passionate
Maybe this is why: Enter = Geofence state outside => Geofence state inside OR Geofence state unknown => Geofence state inside. When geofence is added it's state is unknown.Uterine
C
5

Well, think of Geofences of 3D objects: 2 dimensions in space, one dimension in time. Between the checks, if a Geofence was hit, your new fence got moved into place.

However, I just save the timestamp on adding fences and ignore all hits within seconds after that.

Carolanncarole answered 2/9, 2013 at 2:21 Comment(1)
can you explain in breif? I am facing the same issue.Navarrette
U
4

If you have the following set the geofence will be triggered immediately after it's created, if you're inside the fence.

builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);

However, this is also the default so the trigger will still occur. Setting the trigger to INITIAL_TRIGGER_DWELL does stop the initial trigger from firing it seems:

A flag indicating that geofencing service should trigger GEOFENCE_TRANSITION_DWELL notification at the moment when the geofence is added and if the device is already inside that geofence for some time.

My test device had been in the same location for over an hour and this didn't trigger for that geo fence.

Unbuckle answered 26/2, 2016 at 15:3 Comment(6)
Or simply use the 0 (zero) as parameter to disable initial trigger ;-)Namedropping
Interesting, 0 isn't documented. It's much too late now anyway so I can't even try it out!Unbuckle
Yes it is not documented. But since you can combine for example EXIT and ENTER bitwise using (EXIT | ENTER), and these flags have 2^n values (ENTER = 1, EXIT = 2, DWELL = 4), it is literally logical that the value 0 means none of them ;-)Namedropping
I verified giving 0 as parameter disabled initial trigger. This behavior is logical and it should be documented. In many use cases we want to disable initial trigger.Smuts
I tested with value 0 and it seems that it is working well the behaviour of ENTRANCE and EXIT for Geofence object. :) Why google didn't explain that ?Gluconeogenesis
Update it is documented now that setting initial trigger as 0 will disable the initial triggerDixson
K
3

Sorry If I'm ressurecting an old question, but since I used this answer before I found the correct one, I will just leave it here.

The GeofencingRequest.Builder contains a method (setInitialTrigger) that should solve this issue.

https://developers.google.com/android/reference/com/google/android/gms/location/GeofencingRequest.Builder.html#setInitialTrigger%28int%29

Kitchener answered 22/9, 2015 at 20:35 Comment(0)
T
1

Geofences don't exclusively trigger when the perimeter is crossed. They are triggered when you have been detected anywhere inside the fence and no previous entry event has been sent.

Also note that when a geofence is updated (add geofence with same id again) while you are inside it you will get another entry event as it clears the state of the geofence at the time of update.

Tello answered 10/1, 2014 at 7:49 Comment(0)
M
0

This may help : https://developers.google.com/events/io/sessions/325337477 In the presentation slide (link at the bottom of the page), the accuracy with GPS is ~10 meters.

Militant answered 2/7, 2013 at 1:42 Comment(2)
No help there, still doesn't explain why enter type geofence gets triggered when it's added while we are already inside the radius.Passionate
i did not find the documentation for that behavior (enter transition triggered when app is starting inside a region). But it actually works with my case, since i want to know if i am in the region when i first start the app.Militant

© 2022 - 2024 — McMap. All rights reserved.