alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
117 stars 144 forks source link

Accuracy Calculation #47

Closed dducret closed 4 years ago

dducret commented 4 years ago

Hello,

Thank you very much for your work.

Could you make two changes in your code?

The first to have the value RSSI of type double with precision of 2 decimals.

The second to change the distance calculation (accuracy) http://stackoverflow.com/a/20434019

double calculateAccuracy(int txPower, double rssi){
    if(rssi == 0)
      return -1.0;
    double ratio = rssi*1.0/txPower;
    if(ratio < 1.0)
      return pow(ratio, 10);
    else {
      double accuracy = (0.89976)*pow(ratio,7.7095) + 0.111;
      return num.parse(accuracy.toStringAsFixed(2));
    }
  }
alann-maulana commented 4 years ago

Hi @dducret

Why using these calculation? flutter_beacon use Android-Beacon-Library to provide beacon scanning in Android. The author of these library is the same guy who replying on that stackoverflow link.

Please check the code about distance calculation here https://github.com/AltBeacon/android-beacon-library/blob/master/lib/src/main/java/org/altbeacon/beacon/distance/CurveFittedDistanceCalculator.java#L46-L65.

If you need a precision of the accuracy, you can easily achieve it via Flutter code.