示例中心
功能在线体验
控制台
您现在的位置: 开发 > iOS 导航SDK > 概述 >

高德 开发 iOS 导航SDK 概述

更新时间:2018年09月05日

简介

目前最新版本为 iOS 导航 SDK V6.3.0

6.0.0版本的导航 SDK,全新升级新版导航引擎,导航性能、数据准确度,地图渲染性能全面提升。

iOS 导航 SDK 是一款针对在线导航的产品,产品功能涵盖路径规划、模拟导航、GPS 定位、自定义导航界面、获取导航播报信息等。此外,该产品的导航路径计算与实时交通信息相结合,力求为用户提供更加合理、准确、人性化的导航服务。

面向的读者

iOS 导航 SDK 是提供给具有一定 iOS 编程经验和了解面向对象概念的读者使用的。

  • 模拟导航
    #import "EmulatorNaviViewController.h"
    
    @interface EmulatorNaviViewController ()<AMapNaviDriveManagerDelegate, AMapNaviDriveViewDelegate>
    
    @property (nonatomic, strong) AMapNaviDriveView *driveView;
    @property (nonatomic, strong) AMapNaviPoint *startPoint;
    @property (nonatomic, strong) AMapNaviPoint *endPoint;
    
    @end
    
    @implementation EmulatorNaviViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        //设置导航的起点和终点
        self.startPoint = [AMapNaviPoint locationWithLatitude:39.98 longitude:116.47];
        self.endPoint   = [AMapNaviPoint locationWithLatitude:39.99 longitude:116.45];
    
        //初始化AMapNaviDriveManager
        [[AMapNaviDriveManager sharedInstance] setDelegate:self];
    
        //初始化AMapNaviDriveView
        if (self.driveView == nil)
        {
            self.driveView = [[AMapNaviDriveView alloc] initWithFrame:self.view.bounds];
            [self.driveView setDelegate:self];
        }
    
        //将AMapNaviManager与AMapNaviDriveView关联起来
        [[AMapNaviDriveManager sharedInstance] addDataRepresentative:self.driveView];
        //将AManNaviDriveView显示出来
        [self.view addSubview:self.driveView];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        //路径规划
        [[AMapNaviDriveManager sharedInstance] calculateDriveRouteWithStartPoints:@[self.startPoint]
                                                    endPoints:@[self.endPoint]
                                                    wayPoints:nil
                                              drivingStrategy:AMapNaviDrivingStrategySingleDefault];
    }
    
    //路径规划成功后,开始模拟导航
    - (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager
    {
        [[AMapNaviDriveManager sharedInstance] startEmulatorNavi];
    }
    @end
  • HUD导航模式
    #import "HUDNaviViewController.h"
    #import "SpeechSynthesizer.h"
    
    @interface HUDNaviViewController ()<AMapNaviDriveManagerDelegate, AMapNaviHUDViewDelegate>
    
    @property (nonatomic, strong) AMapNaviHUDView *hudView;
    @property (nonatomic, strong) AMapNaviPoint *startPoint;
    @property (nonatomic, strong) AMapNaviPoint *endPoint;
    
    @end
    
    @implementation HUDNaviViewController
    
    #pragma mark - Life Cycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        [self.view setBackgroundColor:[UIColor whiteColor]];
    
        //设置导航的起点和终点
        self.startPoint = [AMapNaviPoint locationWithLatitude:39.99 longitude:116.47];
        self.endPoint   = [AMapNaviPoint locationWithLatitude:39.98 longitude:116.46];
    
    
        //初始化AMapNaviDriveManager
        [[AMapNaviDriveManager sharedInstance] setDelegate:self];
    
        //初始化AMapNaviHUDView
        if (self.hudView == nil)
        {
            self.hudView = [[AMapNaviHUDView alloc] initWithFrame:self.view.bounds];
            self.hudView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    
            [self.hudView setDelegate:self];
        }
    
        //将AMapNaviManager与AMapNaviHudView关联起来
        [[AMapNaviDriveManager sharedInstance] addDataRepresentative:self.hudView];
        //将AMapNaviHudView显示出来
        [self.view addSubview:self.hudView];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        self.navigationController.navigationBarHidden = NO;
        self.navigationController.toolbarHidden = YES;
    
        //路径规划
        [[AMapNaviDriveManager sharedInstance] calculateDriveRouteWithStartPoints:@[self.startPoint]
                                                    endPoints:@[self.endPoint]
                                                    wayPoints:nil
                                              drivingStrategy:AMapNaviDrivingStrategySingleDefault];
    }
    
    #pragma mark - AMapNaviHUDView Delegate
    //退出hud导航模式的回调,有以下几步:
    //1. 停止导航
    //2. 将AMapNaviDriveManager与AMapNaviHUDView解除绑定
    //3. 停止语音
    //4. 从view中移除AMapNaviHUDView
    - (void)hudViewCloseButtonClicked:(AMapNaviHUDView *)hudView
    {
        [[AMapNaviDriveManager sharedInstance] stopNavi];
        [[AMapNaviDriveManager sharedInstance] removeDataRepresentative:self.hudView];
        //停止语音
        [[SpeechSynthesizer sharedSpeechSynthesizer] stopSpeak];
        [self.hudView removeFromSuperview];
    }
    
    #pragma mark - AMapNaviDriveManager Delegate
    
    //路径规划成功时的回调,开始导航
    - (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager
    {
        //开始模拟导航
        [[AMapNaviDriveManager sharedInstance] startEmulatorNavi];
    }
    @end
  • 多路线规划
    - (void)multipleRoutePlanAction:(id)sender
    {
        //进行多路径规划
        self.isMultipleRoutePlan = YES;
        [[AMapNaviDriveManager sharedInstance] calculateDriveRouteWithStartPoints:@[self.startPoint]
                                                    endPoints:@[self.endPoint]
                                                    wayPoints:nil
                                              drivingStrategy:[self.preferenceView strategyWithIsMultiple:self.isMultipleRoutePlan]];
    }
    
    //选择其中一条路线导航
    [[AMapNaviDriveManager sharedInstance] selectNaviRouteWithRouteID:routeID]
  • 自定义路口放大图
    - (void)driveManager:(AMapNaviDriveManager *)driveManager showCrossImage:(UIImage *)crossImage
    {
        NSLog(@"showCrossImage");
    
        //显示路口放大图
        [self.crossImageView setImage:crossImage];
    }
    
    - (void)driveManagerHideCrossImage:(AMapNaviDriveManager *)driveManager
    {
        NSLog(@"hideCrossImage");
    
        //隐藏路口放大图
        [self.crossImageView setImage:nil];
    }
  • 传入外部GPS数据导航
    - (void)startGPSEmulator
    {
    
        //设置采用外部传入定位信息
        [[AMapNaviDriveManager sharedInstance] setEnableExternalLocation:YES];
    
        [[AMapNaviDriveManager sharedInstance] startGPSNavi];
    
        __weak typeof(self) weakSelf = self;
        [self.gpsEmulator startEmulatorUsingLocationBlock:^(CLLocation *location, NSUInteger index, NSDate *addedTime, BOOL *stop) {
    
            //注意:需要使用当前时间作为时间戳
            CLLocation *newLocation = [[CLLocation alloc] initWithCoordinate:location.coordinate
                                                                    altitude:location.altitude
                                                          horizontalAccuracy:location.horizontalAccuracy
                                                            verticalAccuracy:location.verticalAccuracy
                                                                      course:location.course
                                                                       speed:location.speed
                                                                   timestamp:[NSDate dateWithTimeIntervalSinceNow:0]];
    
            //外部传入定位信息(enableExternalLocation为YES时有效)
            [[AMapNaviDriveManager sharedInstance] setExternalLocation:newLocation isAMapCoordinate:NO];
    
        }];
    }

下载完整示例代码

账号与Key的申请

注册成为高德开发者需要分三步:

第一步,注册高德开发者;

第二步,去控制台创建应用;

第三步,获取Key。

具体步骤可参看下图

获取 API Key

兼容性

2.3.0以下版本支持iOS 6.0及以上系统。

2.3.0及以上版本支持 iOS 7.0及以上系统。

开发者建议

(1) 高德开放平台提供的地图API/SDK,任何非盈利性网站/应用均可免费使用 。请参阅《高德地图 API 使用条款》获得详细信息。

示例中心 功能
在线体验
常见问题