问题
When multiple beacons are detected in the regions,
how can I find that which one is the newest detected one?
Also in beacon exist how can I know that specific beacon has left the region.
回答1:
The typical way to solve this is to combine beacon monitoring and beacon ranging.
You use beacon ranging to read the individual identifiers, and keep a map of what beacons have been seen before like this:
private HashSet<Beacon> beaconsSeen = new HashSet<Beacon>();
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {]
for (Beacon beacon : beacons) {
if (!beaconsSeen.contains(beacon)) {
beaconsSeen.add(beacon);
// Perform your logic here
}
}
}
Since you want the logic to trigger again if the beacon is later rediscovered after all beacons in the region disappear, you must clear the map on region exit:
@Override
public void didExitRegion(Region region) {
beaconsSeen.clear();
}
来源:https://stackoverflow.com/questions/39849297/can-i-get-beacons-data-in-exit-regions-also-how-can-i-detect-when-new-beacon-ent