The Device Nearby example shows how to determine the closest device by comparing the RSSI.
In the real world, you will likely find that the RSSI is practically useless for calculating distance because there are so many factors that affect the signal strength. Having the device on the other side of your body is a common one, but any obstructions including people or furniture, or reflections, make the numbers very inconsistent.
But you can more reliably determine what is most likely a device you are right next to versus the other devices in a room.