跟踪信标

时间:2019-03-22 11:05:22

标签: java android ibeacon beacon android-ibeacon

        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            for (Beacon beacon : beacons) {

                Beacon.setHardwareEqualityEnforced(true);


                    Log.i("MainActivity", "I see a beacon that is about " + beacon.getDistance() + " meters away. ");

            }
        }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
    } catch (RemoteException e) {    }
}

我目前要跟踪3个蓝牙信标,我想写类似的东西

If (beacon.getBluetoothAddress().equals("x") && beacon.getDistance() < beacon2.getDistance() && beacon.getDistance() < beacon3.getDistance()){
Log.i(msg: "beacon1 is the the closest to you");

如何跟踪3个信标?

1 个答案:

答案 0 :(得分:0)

要找到最近的信标,您可以尝试执行以下操作:

        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region){

            String closestBeacon = null;
            for (Beacon beacon : beacons) {
                if (closestBeacon == null)
                    closestBeacon = beacon;
                else {
                    if (closestBeacon.getDistance() > beacon.getDistance()) {
                        closestBeacon = beacon;
                    }
                }
            }

            Log.i(TAG, closestBeacon.getBluetoothAddress() + " beacon is the closest to you");
        }