打开高德官网:http://lbs.amap.com/ ,并注册、登录,在控制台中创建应用,拿到Key值。
开发文档:http://lbs.amap.com/api/ios-indoor-sdk/summary/ ,在下面有相关下载,下载SDK
然后按照开发文档创建和配置工程,另外需要申请室内地图的数据,才能用。
首先,在ViewController里面,导入sdk
#import
#import
然后继承:OIMMapViewDelegate(室内地图),OIMRoutePlanningDelegate(线路规划)
创建对象:
@property (nonatomic,strong) OIMMapView *imapView;
//室内地图路算对象
@property(nonatomic, strong)OIMRoutePlanning* imRoutePlanning;
//路算起点
@property(nonatomic, strong)OIMFeature* selectedFeature;
//路算起点
@property(nonatomic, strong)OIMFeature* routePlanningStart;
在viewDidLoad方法里面初始化OIMMapView
_imapView = [[OIMMapView alloc]initWithFrame:self.view.bounds];
// _imapView.showsIndoorMap = YES;
_imapView.key = App_key;
[_imapView setBuildingId:BuildingId floorNo:1];
_imapView.delegate = self;
_imapView.showRoutePlanning = YES;
_imapView.showLocationPoint = YES;
_imapView.showZoomControl = NO;
[self.view addSubview:_imapView];
其中,App_key是在官网创建应用给的key,BuildingId是申请室内地图数据时,高德给的BuildingId;
然后实现代理方法
#pragma mark - OIMMapViewDelegate
-(void)mapView:(OIMMapView *)mapView didFinishLoadingMap:(NSString *)buildingId floorNo:(int)floorNo
{
}
-(void)mapView:(OIMMapView*)mapView didFailLoadingMap:(NSString*)buildingId floorNo:(int)floorNo withError:(NSError *)error{
[self alert:error.description message:@""];
}
//加载楼层
-(void)mapView:(OIMMapView*)mapView willStartLoadingFloor:(NSString*)buildingId floorNo:(int)floorNo{
}
-(void)mapView:(OIMMapView*)mapView didFinishLoadingFloor:(NSString*)buildingId floorNo:(int)floorNo{
}
/*!
* @brief 点击地图完成
*
* @param mapView 室内地图对象
* @param feature 点击的POI
*
* @since 2.0.0
*/
-(void)mapView:(OIMMapView*)mapView didClickFeature:(OIMFeature*)feature{
//清除所有的选择气泡显示
[self.imapView clearStatus:OIMFeatureStatus_Selected];
//清除所有的高亮显示
[self.imapView setFeature:self.selectedFeature highlight:NO];
//设置点击的对象显示气泡
[self.imapView setFeature:feature status:OIMFeatureStatus_Selected];
//设置点击的对象高亮
[self.imapView setFeature:feature highlight:YES];
self.selectedFeature = feature;
//如果还没有路算起点
if(self.routePlanningStart==nil)
{
//清除路算结果
[self.imapView setShowRoutePlanning:NO];
//设置路算起点
self.routePlanningStart = feature;
//设置路算起点图标
[self.imapView setFeature:feature status:OIMFeatureStatus_RouteStart];
//清除路算终点图标
[self.imapView clearStatus:OIMFeatureStatus_RouteStop];
//清除选择图标
[self.imapView clearStatus:OIMFeatureStatus_Selected];
}
else
{
//显示路算结果
[self.imapView setShowRoutePlanning:YES];
//设置路算终点图标
[self.imapView setFeature:feature status:OIMFeatureStatus_RouteStop];
//清除选择图标
[self.imapView clearStatus:OIMFeatureStatus_Selected];
if(self.imRoutePlanning == nil)
{
//初始化室内路算对象
self.imRoutePlanning = [[OIMRoutePlanning alloc]initWithDelegate:self];
//设置路算对象的KEY
self.imRoutePlanning.key = App_key;
}
//路算请求
[self.imRoutePlanning requestRoutePlanning:BuildingId fromPoiId:self.routePlanningStart.pid toPoiId:feature.pid];
//清除路算起点
self.routePlanningStart = nil;
}
}
这样我们就可以在室内设置起点和终点然后规划路线了。
其实按照sdk的文档,我们可以拿到某个楼层上的所有模块的信息:
NSArray* floorList = [self.imapView getFloorList];
NSLog(@"%@",floorList);
但是他返回的
(
(null)[0]B1,
(null)[0]F1,
(null)[0]F2,
(null)[0]F3,
(null)[0]F4,
(null)[0]F5
)
打断点是
然后我就问高德,最后人家说这不是技术问题,是人家不提供这个功能(我去,早说嘛,害的我还以为配置有问题,重新搞了好几次)。