简体   繁体   English

使用半径内的设备添加地理围栏时从未收到地理围栏停留事件

[英]geofencing dwell event never received when adding geofence with device within the radius

I made a simple test app, setup location and geofencing monitoring using LocationServices.getFusedLocationProviderClient and LocationServices.getGeofencingClient .我使用LocationServices.getFusedLocationProviderClientLocationServices.getGeofencingClient制作了一个简单的测试应用程序,设置位置和地理围栏监控。

I added a geofence using just the dwell transition notification and initial trigger, with the right position and radius such that I was expecting the 'dwell' event very soon after adding the geofence:我仅使用停留过渡通知和初始触发器添加了一个地理围栏,并具有正确的位置和半径,因此我在添加地理围栏后很快就会期待“停留”事件:

geofenceBuilder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL);
...
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL);

In device log I noticed several of these two, each time position was obtained:在设备日志中,我注意到这两个中的几个,每次获得位置时:

在此处输入图片说明

The geofencing pending intent was never triggered.从未触发地理围栏待定意图。 The device was on my desk.该设备在我的桌子上。

I didn't understand what's going on.我不明白发生了什么。 I even tried to switched to Google Maps and switched back to the app, it didn't do anything.我什至尝试切换到谷歌地图并切换回应用程序,它没有做任何事情。 The device is clearly not in any deep sleep since I am using it.自从我使用它以来,该设备显然没有处于任何深度睡眠状态。 So what's in deep sleep?那么深度睡眠是怎么回事呢? I am guessing some geofencing component in Google Play Services?我在猜测 Google Play 服务中的一些地理围栏组件? But the location is being queried constantly by the app, so why doesn't the Google Play Services geofencing sees I am inside the location and send the 'dwell' event?但是该应用程序会不断查询该位置,那么为什么 Google Play 服务地理围栏没有看到我在该位置内并发送 'dwell' 事件?

After I moved around the house with the device, the two log entries didn't appear anymore and I got the geofencing dwell event!在我带着设备在房子里走动后,两个日志条目不再出现,我得到了地理围栏停留事件!

My conclusion is if device\\Android component is in this "sleep" mode when a geofence is being set, I don't think the geofencing events won't fire, at least not the 'dwell' per my tests, as I am writing this I haven't tested to see if 'enter' is called.我的结论是,如果设备\\Android 组件在设置地理围栏时处于这种“睡眠”模式,我认为地理围栏事件不会触发,至少不会触发我的测试中的“停留”,正如我所写我还没有测试过是否调用了“输入”。

What is this "deep sleep mode" and "GeofencerStateMachine" ?这个“深度睡眠模式”和“GeofencerStateMachine”是什么? Is it from Android Google Play services?是否来自 Android Google Play 服务? How does it work?它是如何工作的? What's the reason I didn't get the 'dwell' event?我没有收到 'dwell' 事件的原因是什么?

On another device (Samsung Galaxy) I see same behavior, the dwell event is not received, but there's no similar log entry with 'deep sleep' and moving the device around doesn't make it receive the 'dwell' event...…在另一台设备(三星 Galaxy)上,我看到相同的行为,未收到停留事件,但没有类似的“深度睡眠”日志条目,并且移动设备不会使其收到“停留”事件......

I am logging the device coordinates and I can clearly see the accuracy being around 10 and yet, the dwell event is not being sent.我正在记录设备坐标,我可以清楚地看到精度在 10 左右,但没有发送停留事件。

Update: I left the device on desk for like 40 mins.更新:我把设备放在桌子上大约 40 分钟。 Got back, opened the app, started the geofence, and again, no dwell event being received and now there's not even the log event saying "Location dropped because in deep still mode"... I'm lost...回来,打开应用程序,启动地理围栏,再一次,没有收到停留事件,现在甚至没有日志事件说“位置因为处于深度静止模式而下降”......我迷路了......

Update 2: Even after reinstalling the app it doesn't make the dwell nor the enter events to be received (I also added monitoring for 'enter')更新 2:即使在重新安装应用程序后,它也不会接收到停留或输入事件(我还添加了对“输入”的监控)

Note : Dwell event only occur if you are not already inside the geofence while registering, It will work if you walk inside the geofence after registratoin.注意:停留事件仅在您注册时不在地理围栏内时才会发生,如果您在注册后走进地理围栏内,它将起作用。

You can also try using fake gps to test this and keep on changing the location, worked for me all the time.您也可以尝试使用假 GPS 进行测试并不断更改位置,这一直对我有用。

I have tried following solutions and both worked for me.我尝试了以下解决方案,并且都对我有用。

1st solution is same as your case, as you want to have only dwell event.第一个解决方案与您的情况相同,因为您只想拥有停留事件。


builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL);

builder.setLoiteringDelay(500);
you also have to add this method(time in millis)

2nd solution is for who would like to have all three events 'ENTER','DWELL' & 'EXIT'第二种解决方案适用于希望所有三个事件“进入”、“停留”和“退出”的人

follow the code snippet按照代码片段

// Register your initial trigger with both 'ENTER' & 'DWELL' events
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_DWELL);

//and then set transition types for all three events

.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_DWELL |
 Geofence.GEOFENCE_TRANSITION_EXIT);


//dont forget to add the setLoiteringDelay, in millis

.setLoiteringDelay(5000);

Hope this will for you guys as well.希望这也适用于你们。 I can provide complete working solution if anyone needs it please do comment.如果有人需要,我可以提供完整的工作解决方案,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM