I’m trying to find the closest three beacons nearby, but I’m finding it difficult. I have some code which finds me the closest beacon:
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
Beacon nearestBeacon = findNearestBeacon(beaconsOfInterest);
}
...
private static Beacon findNearestBeacon(List<Beacon> beacons) {
Beacon nearestBeacon = null;
double nearestBeaconsDistance = -1;
for (Beacon beacon : beacons) {
double distance = Utils.computeAccuracy(beacon);
if (distance > -1 &&
(distance < nearestBeaconsDistance || nearestBeacon == null)) {
nearestBeacon = beacon;
nearestBeaconsDistance = distance;
}
}
Log.d(TAG, "Nearest beacon: " + nearestBeacon + ", distance: " + nearestBeaconsDistance);
return nearestBeacon;
}
But how can I convert this to find the closest 3 beacons?