CLBeacon:我如何获得IBeacons的距离? [英] CLBeacon: How can I get the distance from the IBeacons?

查看:117
本文介绍了CLBeacon:我如何获得IBeacons的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取距iBeacons的距离?我可以获取它们的proximity,但是如何获取CLBeacon的距离呢?我使用过Estimote SDK,它提供了距离值,但是我不知道如何使用CLBeacon来获取它.

How can I get the distance from the iBeacons? I am able to get theirproximity, but how can I get the distance from the CLBeacon? I have worked with Estimote SDK, which gives the distance value, but I don't know how I can get it with the 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");
        }
    }];

}

推荐答案

精度属性应该给您一段距离:

Accuracy property should give you a distance:

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

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

If it doesn't work make sure you call startRangingBeaconsInRegion:

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

这篇关于CLBeacon:我如何获得IBeacons的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆