Ios CLBeacon:我怎样才能知道离Ibeacon的距离?

Ios CLBeacon:我怎样才能知道离Ibeacon的距离?,ios,objective-c,xcode,ibeacon,Ios,Objective C,Xcode,Ibeacon,我怎样才能知道到iBeacons的距离?我能够获得他们的接近度,但我如何获得与CLBeacon的距离?我使用过Estimote SDK,它提供了距离值,但我不知道如何使用CLBeacon获得距离值 - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{ if (self.beaco

我怎样才能知道到iBeacons的距离?我能够获得他们的
接近度
,但我如何获得与CLBeacon的距离?我使用过Estimote SDK,它提供了距离值,但我不知道如何使用CLBeacon获得距离值

 - (void)locationManager:(CLLocationManager *)manager
        didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{

    if (self.beaconRegion) {
        if([beacons count] > 0)
        {
            //get closes beacon and find its major
          CLBeacon *beacon = [beacons objectAtIndex:0];
       }
   }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];

    /*
     * Fill the table with beacon data.
     */
    ESTBeacon *beacon = [self.beaconsArray objectAtIndex:indexPath.row];
    beacon.delegate=self;
    cell.textLabel.text = [NSString stringWithFormat:@"Major: %@, Minor: %@", beacon.major, beacon.minor];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Distance: %.2f", [beacon.distance floatValue]];
    [beacon connectToBeacon];
    return cell;
}
-(void)beaconConnectionDidSucceeded:(ESTBeacon *)beacon{
    [beacon writeBeaconProximityUUID:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D" withCompletion: ^(NSString *value, NSError *error){
        if(error){
            NSLog(@"Got error here: %@",[error description]);
        }else{
            NSLog(@"Congratulation! you've got sucessfully written UUID in beacon");
        }
    }];

}

“精度”属性应为您提供一个距离:

CLBeacon *beacon = [beacons objectAtIndex:0];
beacon.accuracy
如果不起作用,请务必致电StarTrangBeaconRegion:

[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];

准确度属性是苹果的估计,即你自己的计算(基于信标的TX和RSSI)的准确度。如果它是“0.1”,这意味着您计算的距离可能不超过10厘米。但如果准确度为“1.5”,而距离计算结果为3米,这意味着信标的范围可能在1.5到4.5米之间

我的猜测是:精度属性测量当前的RSSI,并通过与以前发现的平均RSSI的差异来计算

回答您的问题:您能阅读Java吗?我现在手头没有C代码

    final double ratio_dB = txPower - rssi;
    final double ratio_linear = Math.pow(10, (ratio_dB / 10));
    final double r = Math.sqrt(ratio_linear);

r是以米为单位的估计距离。txPower是信标的Tx功率(对于AltBeacons,这是有效载荷在20字节“信标ID”后的字节1)。

精度是非常近似的距离,单位为米。它非常容易出错,并且会根据您手持手机的方式、您的身体是否在您和信标之间、附近的其他人、墙壁金属物体等而有所不同。您还应该知道,您可以校准硬件。iBeacon有一个Tx值,可根据1米处的RSSI进行设置。这可能会对距离估计产生很大影响。我还注意到,它在苹果的文档中明确指出,“不要用它(准确度)来确定信标的精确位置。”