Skip to content

智石科技 室内地图 iOS API

简介

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

准备工作

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

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

开发指南

集成SDK

1、下载开发包

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

2、引入地图定位库

  • 公共资源库:[BRTMapData.framework]
  • 地图支撑库:[BRTMapSDK.framework],[Mapbox.framework],[geos.a]
  • 定位支撑库:[BRTLocationEngine.framework]

注意:请将Mapbox.framework添加到Build Phases->Embed Frameworks,并添加指向文件中的RunScript:

BASH
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework/strip-frameworks.sh"

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

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

创建显示地图

objective-c
#import <BRTMapSDK/BRTMapSDK.h>
@interface viewController<BRTMapViewDelegate>
@property (nonatomic,strong) BRTMapView *mapView;
@end

初始化地图view,设置加载你的建筑ID和AppKey参数。

objective-c
self.mapView = [[BRTMapView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.mapView];
[self.mapView setDelegate:self];
[self.mapView loadWithBuilding:_buildingID appkey:_appKey];

常用API展示

地图展示

1、设置楼层
objective-c
 [mapView setFloor:1];
2、设置缩放
objective-c
[mapView setZoomLevel:022];
3、设置旋转
objective-c
[mapView setDirection:0360];
4、设置倾斜
objective-c
MGLMapCamera *camera = self.mapView.camera;
camera.pitch = 0~60;
[mapView setCamera:camera];
5、坐标转换
objective-c
CLLocationCoordinate2D *coord = [mapView convertPoint:
screen toCoordinateFromView:mapView]
CGPoint *screen = [mapView convertCoordinate:mapView.centerCoordinate       
toPointToView:self.view]

地图控制

1. 移动中心点
objective-c
[mapView setCenterCoordinate:coord animated:YES];
2. 移动相机
objective-c
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate: toPoint fromDistance:20 pitch:50 heading:90];
[mapView flyToCamera:camera withDuration:6 peakAltitude:20 completionHandler:nil];

手势控制

1. 旋转控制
objective-c
mapView.rotateEnabled = ;
2. 缩放控制
objective-c
mapView.zoomEnabled = ;
3. 滑动控制
objective-c
mapView.scrollEnabled = ;
4. 倾斜控制
objective-c
mapView.pitchEnabled = ;
5. 多点控制
objective-c
mapView.multipleTouchEnabled = ;

地图控件

1. 比例尺控件
objective-c
self.mapView.showsScale = YES;
2. 指南针控件
objective-c
self.mapView.compassView.hidden = YES;

事件监听

1. 加载地图回调
objective-c
(void)mapViewDidLoad:(BRTMapView *)mapView withError:(NSError *)error
2. 地图楼层切换
objective-c
(void)mapView:(BRTMapView *)mapView didFinishLoadingFloor:(BRTFloorInfo *)floorInfo
3. Poi选中
objective-c
(void)mapView:(BRTMapView *)mapView poiSelected:(NSArray *)array
4. 地图点击
objective-c
(void)mapView:(BRTMapView *)mapView poiSelected:(NSArray *)array
5. 地图缩放、倾斜、滑动、旋转等区域改变事件回调
objective-c
(void)mapViewRegionIsChanging:(BRTMapView *)mapView;

地图标注

1. 点标注
objective-c
//添加点标注
MGLPointAnnotation *hello = [[MGLPointAnnotation alloc] init];
hello.coordinate = self.mapView.centerCoordinate;
hello.title = @"Hello world!";
hello.subtitle = @"Welcome to my marker";
[mapView addAnnotation:hello];

//可以仅使用图片标注,效率高
- (MGLAnnotationImage *)mapView:(BRTMapView *)
mapView imageForAnnotation:(id)annotation
MGLAnnotationImage *annotationImage = 
[mapView dequeueReusableAnnotationImageWithIdentifier:@"location"];
if (!annotationImage) {
    UIImage *image = [UIImage imageNamed:@"location"];
    annotationImage = [MGLAnnotationImage annotationImageWithImage:
    image reuseIdentifier:@"location"];
}

    return annotationImage;
}
//设置任意标注的view,性能较低
- (MGLAnnotationView *)mapView:(BRTMapView *)mapView viewForAnnotation:(id)annotation {
//use title for example reuseid
NSString * reuseIdentifier =  annotation.title;
MGLAnnotationView *annotationView = 
[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
    if (!annotationView) {
    annotationView = [[MGLAnnotationView alloc] initWithReuseIdentifier:reuseIdentifier];
    annotationView.frame = CGRectMake(0, 0, 40, 40);
    }
    return annotationView;
}
2. 线 / 面标注
objective-c
//设置标注等tint颜色
mapView.tintColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.99];
//添加线标注
MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:mapCoords count:4];
[mapView addAnnotation:polyline];
//添加面(多边形)标注
MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:polygonCoords count:index];
[mapView addAnnotation:polygon];
3. 弹窗事件
objective-c
//允许弹出
- (BOOL)mapView:(BRTMapView *)mapView annotationCanShowCallout:
(id)annotation {
    return YES;
}

//弹窗左视图
- (UIView *)mapView:(BRTMapView *)
mapView leftCalloutAccessoryViewForAnnotation:(id)annotation {
    return [UIButton buttonWithType:UIButtonTypeContactAdd];
}

//弹窗右视图
- (UIView *)mapView:(BRTMapView *)mapView rightCalloutAccessoryViewForAnnotation:(id)
annotation {
    return [UIButton buttonWithType:UIButtonTypeInfoLight];
}

- (UIView*)mapView:(BRTMapView *)mapView calloutViewForAnnotation:(id)annotation
{
    // Instantiate and return our custom callout view.
    // 自定义弹窗View
}

POI查询

1. 地图查询
objective-c
//根据屏幕坐标x和y提取当前楼层的ROOM POI
- (NSArray*)extractPoiOnCurrentFloorWithPoint:(CGPoint)point;
//地图POI选中事件回调
- (void)mapView:(BRTMapView *)mapView poiSelected:(NSArray *)array;
//获取当前楼层下特定子层特定poiID的信息
- (BRTPoi *)getPoiOnCurrentFloorWithPoiID:(NSString *)pid layer:(POI_LAYER)layer;
//获取本层车位Poi
- (NSArray*)getParkingSpacesOnCurrentFloor;
//获取本层设施数据
- (NSArray*)getAllFacilityOnCurrentFloor;
//条件筛选poi数据
- (NSArray*)getPoiUsingPredicate:(NSPredicate *)predicate;
2. 数据查询
objective-c
//初始化数据查询,设置名称去重范围(米)
BRTSearchAdapter *adapter = [[BRTSearchAdapter alloc] initWithBuildingID:
建筑id distinct:1.0];
//名称搜索
- (NSArray*)queryPoi:(NSString *)name andFloor:(int)floor;
//根据自定sql检索POI名称
- (NSArray*)querySql:(NSString *)sql;
//根据关键字模糊检索所有楼层POI名称
- (NSArray*)queryPoi:(NSString *)searchText;
//根据关键字模糊和楼层检索POI名称
- (NSArray*)queryPoi:(NSString *)name andFloor:(int)floor;
//根据类别ID检索所有楼层POI
- (NSArray*)queryPoiByCategoryID:(NSString *)cids;
//根据类别ID和楼层检索POI
- (NSArray*)queryPoiByCategoryID:(NSString *)cids andFloor:(int)floor;
//搜索point半径约radius范围内floor楼层的poi
- (NSArray*)queryPoiByCenter:(CLLocationCoordinate2D)
point Radius:(double) radius Floor:(int) floor;

路径规划

1. 路径标记
objective-c
//设置导航线的起点图标
- (void)setRouteStartSymbol:(UIImage *) image;
//设置导航线的终点符号
- (void)setRouteEndSymbol:(UIImage *) image;
//设置跨层导航切换点符号
- (void)setRouteSwitchSymbol:(UIImage *) image;
//设置导航线符号
- (void)setRouteColor:(UIColor *)color; 
//设置导航经过线符号
- (void) setPassedRouteColor:(UIColor *)color;
2. 在线规划
objective-c
self.mapView.routeManager.delegate = self;
[self.mapView.routeManager requestRouteWithStart:self.
startLocalPoint     
End:self.endLocalPoint];

//在线路径规划回调
- (void)routeManager:(BRTRouteManager *)
routeManager didSolveRouteWithResult:(BRTRouteResult *)rs
- (void)routeManager:(BRTRouteManager *)
routeManager didFailSolveRouteWithError:(NSError *)error
3. 离线规划
objective-c
BRTOfflineRouteManager  *offlineRouteManager = 
[BRTOfflineRouteManager routeManagerWithBuilding:self.mapView.building MapInfos:
self.mapView.floorInfos];
offlineRouteManager.delegate = self;

#pragma mark - **************** 离线路径规划回调
- (void)offlineRouteManager:(BRTOfflineRouteManager *)
routeManager didFailSolveRouteWithError:(NSError *)error
- (void)offlineRouteManager:(BRTOfflineRouteManager *)
routeManager didSolveRouteWithResult:(BRTRouteResult *)rs
4. 显示路径
objective-c
[mapView setRouteResult:rs];
[mapView showRouteResultOnCurrentFloor];
5. 导航描述
objective-c
//获取localPoint附近的导航路段part
BRTRoutePart *part = [routeResult getNearestRoutePart:localPoint];
//获取part上所有导航描述(忽略5米,10度角)
NSArray *routeGuides = [part getRouteDirectionalHintsIgnoreDistance:5 angle:10];
//或者localPoint附近的导航描述
BRTDirectionalHint *hint = [part getDirectionHintForLocation:localPoint  
FromHints:routeGuides];

显示导航

1. 定位点
objective-c
[self.mapView showLocation:localPoint];
[self.mapView removeLocation];
2. 显示经过路段
objective-c
- (void)showPassedAndRemainingRouteResultOnCurrentFloor:(BRTLocalPoint *)lp;
3. 显示余下路段
objective-c
- (void)showRemainingRouteResultOnCurrentFloor:(BRTLocalPoint *)lp;
4. 全路网吸附
objective-c
- (BRTLocalPoint *)nearestPointOnRoute:(BRTLocalPoint *)point;
5. 导航路段BRTRouteResult吸附
objective-c
BRTLocalPoint *location = [routeResult getNearPointOnRoute: point];

关于