Konstantin.Efimenko
Konstantin.Efimenko

Reputation: 1450

How to increase time of accuracy calculation?

Interesting case: if we move iPhone to iBeacon device, value of accuracy changed much faster than when we move iPhone from device. How can I make this process faster?

Upvotes: 0

Views: 81

Answers (1)

davidgyoung
davidgyoung

Reputation: 64941

As you have noted, CoreLocation averages past signal measurements to come up with an accuracy calculation (distance estimate in meters). The algorithm used to do the averaging is unpublished, but my measurements have shown a lag that stabilizes after about 20 seconds. I have not noticed a difference in lag between getting closer or further away.

You have no control over this averaging interval. The only thing you can do is average RSSI yourself over whatever time period you wish. You can then use a custom calculation to convert average RSSI to distance.

To do this you will need to have beacons that all have identical transmitter power, as you will not have access to the measured power calibration constant in the beacon advertisement. (Apple does not allow reading this value.). Instead, this constant must be hard coded in your customer distance calculation.

You can see sample code that does this here:

+(double) distanceForRSSI:(double)rssi forPower:(int)txPower {
  // use coefficient values from spreadsheet for iPhone 4S
  double coefficient1 = 2.922026; // multiplier
  double coefficient2 = 6.672908; // power
  double coefficient3 = -1.767203; // intercept

  if (rssi == 0) {
    return -1.0; // if we cannot determine accuracy, return -1.0
  }

  double ratio = rssi*1.0/txPower;
  double distance;

  if (ratio < 1.0) {
    distance =  pow(ratio,10);
  }
  else {
    distance =  (coefficient1)*pow(ratio,coefficient2) + coefficient3;
  }

  if (distance < 0.1) {
    NSLog(@"Low distance");
  }

  return distance;
}

https://github.com/AltBeacon/ios-beacon-tools/blob/master/ios-beacon-tools/RNLBeacon%2BDistance.m

Upvotes: 1

Related Questions