簡體   English   中英

CLBeacon:我如何獲得IBeacons的距離?

[英]CLBeacon: How can I get the distance from the IBeacons?

如何獲得距iBeacons的距離? 我能夠proximity他們,但是我如何與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

如果它不起作用,請確保調用startRangingBeaconsInRegion:

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

准確性屬性是Apple的估計,即您自己的計算(基於信標的TX和RSSI)可以達到的精確程度。 如果為“ 0.1”,則意味着您計算出的距離可能不超過10厘米。 但是,如果精度為“ 1.5”,並且您的距離計算結果為3m,則表示信標的范圍可能在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-Power(對於AltBeacons,這是有效載荷的字節,在20個字節的“信標ID”之后)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM