IOS 高德地图导航
引言
高德地圖導航包還是淺顯易懂,筆者在這里做點總結,實際操作一遍。
導航分為模擬導航和實時導航兩種,兩種導航都包括語音提示、停止導航、暫停或繼續導航功能。通過模擬導航,用戶可預先了解出行路線,直觀掌握沿途每一個特別路口的交通狀況,讓出行更從容。
算路成功后就可在導航視圖或HUD視圖下開始導航了,如下圖所示:
1.配置工程
筆者是使用cocoapods自動部署導航SDK,如果更新了cocoa pods,現在編寫podfile文件有點不一樣。以下實例:
platform :ios, ‘8.0’
use_frameworks!
target ‘約車’ do
pod ‘AMap3DMap’
pod ‘AMapSearch’
pod ‘AMapLocation’
pod ‘AMapNavi’
end
2.配置key
導入工程之后,我們需要在高德地圖平臺申請應用的key作為唯一標識,可參見官方文檔,關于配置key筆者在此就不贅述。
3.實施
配置好之后,在viewController中導入
我們以標準導航視圖為例:
(1)
獲取自身位置不是必須的,我們可以使用高德地圖導航SDK中的另外一種方法規劃駕車路徑,不帶起點的路徑規劃(以自身位置為七點)。
- (BOOL)calculateDriveRouteWithEndPoints:(NSArray<AMapNaviPoint *> *)endPointswayPoints:(nullable NSArray<AMapNaviPoint *> *)wayPointsdrivingStrategy:(AMapNaviDrivingStrategy)strategy; //初始化標準導航視圖 - (void)initNaviDriveView {if (self.naviDriveView == nil){self.naviDriveView = [[AMapNaviDriveView alloc] initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];self.naviDriveView.delegate = self;//導航界面模式self.naviDriveView.showMode = AMapNaviDriveViewShowModeCarPositionLocked;//導航界面跟隨模式self.naviDriveView.trackingMode = AMapNaviViewTrackingModeCarNorth;} } /*標準導航視圖回調方法*/ - (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager {//將naviDriveView添加到AMapNaviDriveManager中/*** 在這里可以修改用哪個模式 標準或者HUD*/[self.driveManager addDataRepresentative:self.naviDriveView];//將導航視圖添加到視圖層級中[self.view addSubview:self.naviDriveView];//開始實時導航[self.driveManager startGPSNavi]; }- (void)initDriveManager {if (self.driveManager == nil) {self.driveManager = [[AMapNaviDriveManager alloc] init];[self.driveManager setDelegate:self];//開啟智能播報,包括路面電子眼,路障等等。。。[self.driveManager setDetectedMode:AMapNaviDetectedModeCameraAndSpecialRoad];} }//語音播報 -(void)driveManager:(AMapNaviDriveManager *)driveManager playNaviSoundString:(NSString *)soundString soundStringType:(AMapNaviSoundType)soundStringType {if (soundStringType == AMapNaviSoundTypePassedReminder){AudioServicesPlaySystemSound(1009);//播放系統“叮叮”提示音}else{[[SpeechSynthesizer sharedSpeechSynthesizer] speakString:soundString];} }SpeechSynthesizer 語音播報文件可參考Demo
AudioServicesPlaySystemSound(1009);//播放系統“叮叮”提示音 需要導入頭文件<AudioToolbox/AudioToolbox.h>至此,標準導航視圖創建成功。如果你想使用HUD導航視圖,只需要
//初始化HUD導航視圖 - (void)initHudView {if (self.hudView == nil){self.hudView = [[AMapNaviHUDView alloc] initWithFrame:CGRectMake(0, 64, 375, 667)];self.hudView.delegate = self;self.hudView.isMirror = NO;//是否開啟鏡像} }只需要在下面這個回調方法中將標準導航視圖設置成HUD視圖即可
- (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager以上來源于高德地圖導航SDK的一些歸納
總結
以上是生活随笔為你收集整理的IOS 高德地图导航的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PASCAL VOC2012数据集介绍与
- 下一篇: GB35114---SM3withSM2