Search code examples
iosobjective-cibeaconproximity

Get Distance From CLProximity


i am developing a beacon detecting app using objective c and i am getting beacon value as follow

CLBeacon (uuid:<__NSConcreteUUID 0x174223ee0> XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, major:0, minor:1, proximity:2 +/- 0.32m, rssi:-49)

in this value i want to get the proximity as +/- 0.32m value but then i am accessing the proximity value i am not getting it how can i access this value can anyone help me with this i am using newest IOS SDK


Solution

  • CLProximity will not tell the distance in meters It will just give you value in

    CLProximityUnknown,
    CLProximityImmediate,
    CLProximityNear,
    CLProximityFar
    

    To find distance in meters (for example beacon is in range of 15 meters) you need look this document. The formula is #19 on page 3 and basically it does this:

    Received Signal Strength is related to distance using the equation below.
    RSSI [dBm] = -10n log10 (d) + A [dBm] 
    

    Where
    A is the received signal strength in dBm at 1 meter - you need to calibrate this on your system. Because you are calibrating at a known distance you don't need to take into account the frequency of your transmission and this simplifies the equation. (Just place the iBeacon to 1 meters range, and measure it's RSSI)

    n is the propagation pathloss exponent i.e. 2.7 to 4.3 (Free space has n = 2 for reference, if there are walls it will be greater).

    d is the distance from the sender in meters

    So you have all values, except d, you need to calculate d by using mentioned formula.

    EDIT: Accuracy
    CoreLocation also provides accuracy property for CLBeacon. You are right it's provided in meters, but shows how accurate is the measurement.

    In you case it shows that beacon proximity is CLProximityNear, and it's accurate by +/- 0.32m.

    Here is documentation about accuracy

    /*
     *  accuracy
     *
     *  Discussion:
     *    Represents an one sigma horizontal accuracy in meters where the measuring device's location is
     *    referenced at the beaconing device. This value is heavily subject to variations in an RF environment.
     *    A negative accuracy value indicates the proximity is unknown.
     *
     */
    @property (readonly, nonatomic) CLLocationAccuracy accuracy;