Skip to content

智石科技 室内定位 iOS API

简介

智石科技室内定位 iOS API,是由 Objective-C 语言编写的应用程序接口,它能够帮助您移动端中实现iBeacon定位导航。开发包最低兼容IOS7及其以上系统。

准备工作

进行室内地图和定位开发的准备工作:

  • 您需要成为智石的用户;
  • 获取BuildlingID、Appkey,请在(开放平台>建筑与地图>建筑管理)中查看;

开发指南

集成SDK

1、下载开发包

https://github.com/BrightBeacon/IndoorPositionSDK-IOS

2、引入地图定位库

3、需配置定位/蓝牙权限描述字符串

  • 打开Info.plist添加蓝牙描述说明:NSBluetoothAlwaysUsageDescription,(填写描述如:使用蓝牙进行室内定位)
  • 打开Info.plist添加使用期间“WhenInUse”定位描述说明:NSLocationWhenInUseUsageDescription,(填写描述如:使用室内定位进行导航)
  • 若应用需要使用后台及使用期间定位权限“Always”(含“WhenInUse”),需添加3项以支持不同IOS版本:NSLocationAlwaysAndWhenInUseUsageDescription、NSLocationAlwaysUsageDescription和NSLocationWhenInUseUsageDescription

创建定位功能

1. 初始化定位

objective-c
//初始化定位数据
self.locationManager = [[BRTLocationManager alloc] initWithBuilding:self.mapView.building appKey:kAppKey];
self.locationManager.delegate = self;

//开始定位
[self.locationManager startUpdateLocation];

//页面退出时候,请停止定位
//[self.locationManager stopUpdateLocation];

2. 定位结果回调

objective-c
#pragma mark - **************** 定位回调方法

//返回beacon信号实时定位结果,固定1s/次,位置变化会立即更新,可能引起频繁跳动,一般用于快速移动
- (void)BRTLocationManager:(BRTLocationManager *)manager didUpdateImmediateLocation:(BRTLocalPoint *)newImmediateLocation {
	//不要和didUpdateLocation同时显示位置,会导致位置跳动
	//[self.mapView showLocation:newImmediateLocation];
}

//返回定位 + 陀螺仪等优化定位,最快0.2s/次,加入陀螺仪判定,位置变化相对较稳定,一般用于慢速移动
- (void)BRTLocationManager:(BRTLocationManager *)manager didUpdateLocation:(BRTLocalPoint *)newLocation {
	[self.mapView showLocation:newLocation];
}

/**
*  位置更新失败事件回调(定位数据异常,定位超时等错误)
*  @param manager 定位引擎实例
*/
- (void)BRTLocationManager:(BRTLocationManager *)manager didFailUpdateLocation:(NSError *)error {
	NSLog(@"定位失败:%@",error);
}

/**
*  Beacon扫描结果事件回调,返回符合扫描参数的所有Beacon
*  @param manager 定位引擎实例
*  @param beacons Beacon数组,[BRTBeacon]
*/
- (void)BRTLocationManager:(BRTLocationManager *)manager didRangedBeacons:(NSArray *)beacons {
	// NSLog(@"all beacons find:%@",beacons);
}

/**
*  定位Beacon扫描结果事件回调,返回符合扫描参数的定位Beacon,定位Beacon包含坐标信息。此方法可用于辅助巡检,以及基于定位beacon的相关触发事件。
* @param manager 定位引擎实例
* @param beacons 定位Beacon数组,[BRTPublicBeacon]
*/
- (void)BRTLocationManager:(BRTLocationManager *)manager didRangedLocationBeacons:(NSArray *)beacons {
	//显示扫描到的Beacon设备信息
	[self.mapView removeAnnotations:self.mapView.annotations];
	NSMutableArray *marray = [NSMutableArray array];
	NSInteger i = 0;
	for (BRTPublicBeacon *pb in beacons) {
    	if (pb.location.floor == self.mapView.currentFloor) {
            MGLPointAnnotation *ann = [[MGLPointAnnotation alloc] init];
            ann.coordinate = pb.location.coordinate;
            ann.title = [pb.minor.stringValue stringByAppendingFormat:@",%d(%ld)",pb.rssi,++i];
            [marray addObject:ann];
    	}
	}
	[self.mapView addAnnotations:marray];
}

/**
*  设备方向改变事件回调。地图正北方向回调。
*  @param manager    定位引擎实例
*  @param mapHeading 设备正北方向+地图正北偏角(源于building.initAngle或locationManager初始化传入参数)
*/
- (void)BRTLocationManager:(BRTLocationManager *)manager didUpdateMapHeading:(double)mapHeading {
	NSLog(@"室内地图北偏角:%f",mapHeading);
	[self.mapView processDeviceRotation:mapHeading];
}

/**
*  设备方向改变事件回调。设备正北方向回调。
*  @param manager    定位引擎实例
*  @param mapHeading 设备正北方向
*/

- (void)BRTLocationManager:(BRTLocationManager *)manager didUpdateDevicepHeading:(double)deviceHeading {
	NSLog(@"手机北偏角:%f",deviceHeading);
}

关于