Jen*_*ens 15 java android android-geofence
我有一个问题了解Androids geofences.
实际问题:我使用googles geofence-api中的Enter+ Exit事件,但在许多设备上,信号是如此不准确,以至于它跳入和跳出栅栏(跳跃经常大于半径400m).
计划解决方案:所以我想用它Dwell来"平滑"这个.如果位置在栅栏内保持一分钟,则会发生停留.到现在为止还挺好.但是如何检测围栏的离开?当我使用时Exit,Exit由于那些信号跳跃,可能会发生几次.当我离开地理围栏超过一分钟时,我需要的是一种"不适应".
我想避免使用自定义逻辑重新实现整个Geofence,该逻辑在快速重复的地理位置上进行注册并过滤掉小的异常值.
问题:geofence-api中有什么东西可以实现"不适"吗?或者是否有最佳实践如何检查是否Exit真的退出?
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
895 次 |
| 最近记录: |