CLBeacon:如何获取与iBeacons的距离?

5

我该如何获取iBeacons的距离?我能够获取它们的proximity,但是如何从CLBeacon获取距离呢?我已经使用Estimote SDK进行了开发,这个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");
        }
    }];

}
2个回答

10

准确性属性应该给你一个距离:

CLBeacon *beacon = [beacons objectAtIndex:0];
beacon.accuracy

如果不起作用,请确保调用startRangingBeaconsInRegion:

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

1
准确度是一个非常近似的距离,以米为单位。它非常容易出错,并且会根据您握手机的方式、您与信标之间是否有身体、附近的其他人、墙壁金属物体等因素而变化。 - Duncan C
1
你还应该知道,你可以校准硬件。iBeacon有一个Tx值,可以根据1米处的RSSI设置。这可以在距离估计中产生很大的差异。 - csexton
1
我还要指出的是,苹果的文档明确指出:“不要使用它(准确性)来确定信标的精确位置。” - Ash

0

准确性属性是苹果的估计,它可以衡量你基于信标的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”后面的有效负载字节之一)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接