Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ginixsan/3858f5a7889c5f29f18d72974a8f412b to your computer and use it in GitHub Desktop.
Save ginixsan/3858f5a7889c5f29f18d72974a8f412b to your computer and use it in GitHub Desktop.
iBeacon calculate distance in meters
// Based on http://stackoverflow.com/a/20434019
function calculateAccuracy(txPower, rssi) {
if (rssi === 0) {
return -1; // if we cannot determine accuracy, return -1.
}
var ratio = rssi * 1 / txPower;
if (ratio < 1.0) {
return Math.pow(ratio, 10);
} else {
return (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment