iOS 高德室内地图导航功能的简单实现

打开高德官网:http://lbs.amap.com/ ,并注册、登录,在控制台中创建应用,拿到Key值。

点击iOS室内地图SDK

开发文档:http://lbs.amap.com/api/ios-indoor-sdk/summary/ ,在下面有相关下载,下载SDK

然后按照开发文档创建和配置工程,另外需要申请室内地图的数据,才能用。





首先,在ViewController里面,导入sdk

#import <IndoorMapSDK/IndoorMapSDK.h>

#import <OnlineLocationSDK/OnlineLocationSDK.h>

然后继承: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是在官网创建应用给的keyBuildingId是申请室内地图数据时,高德给的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

)

打断点是


然后我就问高德,最后人家说这不是技术问题,是人家不提供这个功能(我去,早说嘛,害的我还以为配置有问题,重新搞了好几次)

所以就不要纠结了。安卓的可以试试,看看行不行。

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值