Android 安卓&x2B;估计信标:获取最近的信标

Android 安卓&x2B;估计信标:获取最近的信标,android,bluetooth-lowenergy,estimote,Android,Bluetooth Lowenergy,Estimote,我正在制作一个应用程序,它使用可移动信标。我们正在使用Estimote信标及其框架。我在我的应用程序中添加了检测 检测成功,我可以使用以下代码获取信标列表: this.beaconManager = new BeaconManager(this); this.beaconManager.setRangingListener(new BeaconManager.BeaconRangingListener() { @Override public void onBeaconsDisc

我正在制作一个应用程序,它使用可移动信标。我们正在使用Estimote信标及其框架。我在我的应用程序中添加了检测

检测成功,我可以使用以下代码获取信标列表:

this.beaconManager = new BeaconManager(this);
this.beaconManager.setRangingListener(new BeaconManager.BeaconRangingListener() {
    @Override
    public void onBeaconsDiscovered(BeaconRegion beaconRegion, List<Beacon> list) {

        if (!list.isEmpty()) {
            MainActivity.this.updateClosestBeacon(list);
        }
        else {
            txtClosest.setText("No beacons detected");
        }
    }
});

this.beaconRegion = new BeaconRegion("monitored region",
        UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"),
        null, null);


beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
    @Override
    public void onServiceReady() {
        beaconManager.startRanging(beaconRegion);
    }
});
this.beaconManager=新的beaconManager(this);
this.beaconManager.setRangingListener(新的beaconManager.BeaconRangingListener(){
@凌驾
发现BeaconRegion上的公共无效(BeaconRegion BeaconRegion,列表){
如果(!list.isEmpty()){
MainActivity.this.updateClosestBeacon(列表);
}
否则{
setext(“未检测到信标”);
}
}
});
this.beaconRegion=新的beaconRegion(“监控区域”,
UUID.fromString(“B9407F30-F5F8-466E-AFF9-25556B57FE6D”),
空,空);
connect(新的beaconManager.ServiceReadyCallback(){
@凌驾
服务日上的公共无效(){
beaconManager.启动(beaconRegion);
}
});
updateClosestBeacon函数使用以下两个函数获取信标:

private static Comparator<Beacon> COMPARATOR = new Comparator<Beacon>()
{
    // This is where the sorting happens.
    public int compare(Beacon o1, Beacon o2)
    {
    return o2.getRssi() - o1.getRssi();
    }
};


public Beacon getClosestBeacon(List<Beacon> list){

    if(list.isEmpty())
        return null;

    Collections.sort(list, COMPARATOR);

    return list.get(0);
}
private static Comparator Comparator=new Comparator()
{
//这就是进行排序的地方。
公共整数比较(信标o1、信标o2)
{
返回o2.getRssi()-o1.getRssi();
}
};
公共信标getClosestBeacon(列表){
if(list.isEmpty())
返回null;
集合。排序(列表、比较);
返回列表。获取(0);
}
我按rssi排序信标列表,然后得到第一个。这不正常。我在estimote论坛上寻找答案,但在那里我找不到答案,只有一些显示灯塔探测的视频链接

你能给我一些代码来帮助我处理信标列表并得到最近的信标吗


感谢您的帮助

RSSI是一种不准确的方法,有些人会说这种方法不适合确定相对距离。RSSI受到许多因素的影响,如障碍物、多径衰落、天线极化和跨体屏蔽。相反,人们可以尝试观察一种趋势,尽管它不一定能保证区分两个设备距离之间的距离。@CzarMatt我不确定我是否理解什么是趋势。你能给我举个例子吗?
比较器
代码有什么作用吗?“工作不正常”是什么意思?根据我使用BLE信标的经验,我建议您比较多个RSSI值的平均值,而不是比较单个值。一般来说,RSSI不是常数,因此最近的信标有时没有获得最高的RSSI值。