浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
步行导航
下载开发文档
步行导航简介

iOS 地图SDK自V4.2.0版本起新增步行导航功能,支持普通步行导航、步行AR导航、偏航纠偏等导航功能。

步行导航功能实现
1. 注册监听

步行导航提供给开发者监听,步行多路线规划回调、步行导航算路回调、导航状态回调、诱导信息回调、TTS语音播报文本。

使用方法如下:

BMKWalkNavigationManager *manager = [BMKWalkNavigationManager sharedManager];
manager.walkNaviMode = BMK_WALK_NAVIGATION_MODE_WALK_NORMAL;
manager.enableMultiRoute = YES; // 设置是否支持多路线 since 6.5.4
manager.routePlanDelegate = self; // 设置多路线规划回调,支持关键字 since 6.5.4
manager.routeGuidanceDelegate = self; // 设置导航状态信息回调
manager.ttsPlayerDelegate = self; //设置语音播报回调
manager.managerDelegate = self; // 设置导航状态回调,如退出导航
manager.calcRouteDelegate = self; // 算路回调,只支持经纬度算路,区别于多路线规划回调 since 6.5.4
manager.locationAuthorizationDelegate = self;
// 启用后台位置指示器,进入后台时保留被授予的临时访问权限(精确位置)
[manager showsBackgroundLocationIndicator:YES];
2. 引擎初始化

开始步行导航前,需要进行步行导航引擎初始化。

使用方法如下:

//由开发者提供导航页面
WalkNaviViewController *controller = [[WalkNaviViewController alloc] init];
//初始化
BOOL inited = [[BMKWalkNavigationManager sharedManager] initNaviEngine:controller];
if (inited) {
//初始化成功,发起算路...
}
3. 发起算路

引擎初始化成功之后,发起导航算路。since 6.5.4版本后支持多路线路线规划,规划后用户可以选择合适的路线进行导航使用方法如下:

BMKWalkNaviLaunchParam *param = [[BMKWalkNaviLaunchParam alloc] init];
BMKWalkNaviRouteNodeInfo *startNode = [[BMKWalkNaviRouteNodeInfo alloc] init];
startNode.location = _startAnnotation.coordinate; // 设置起点
BMKWalkNaviRouteNodeInfo *endNode = [[BMKWalkNaviRouteNodeInfo alloc] init];
endNode.location = _endAnnotation.coordinate; // 设置终点
param.startNode = startNode;
param.endNode = endNode;
// 设置算路方式
param.startNode.type = BMKWalkNavigationRouteNodeLocation;
param.endNode.type = BMKWalkNavigationRouteNodeLocation;
[[BMKWalkNavigationManager sharedManager] routePlanWithParams:param];
4. 弹出导航页面

算路成功后,即可以执行弹出导航页面(即引擎初始化时传入的参数controller)操作,since 6.5.4版本后,可先展示多条路线,选择路线后进入导航页面。使用方法如下:

#pragma mark - BMKWalkCycleRoutePlanDelegate
/**
开始算路
*/
- (void)onRoutePlanStart:(BMKWalkCycleNavigationType)naviType {
NSLog(@"SDK-开始步行路线规划");
}
- (void)onRoutePlanResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType{
if (errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS) {
NSLog(@"SDK-算路成功");
if (naviType == BMK_WALK_CYCLE_NAVIGATION_TYPE_WALK) {
[self.mapView removeOverlays:self.mapView.overlays];
// 展示多路线
_routePolylines = [[BMKWalkNavigationManager sharedManager] displayRoutePlanResult:_mapView];
if (_routePolylines.count == 1) {
// 只有一条时直接使用该路线进行引擎算路,成功后进入导航页面
[[BMKWalkNavigationManager sharedManager] naviCalcRoute:0];
}
}
} else {
NSLog(@"SDK-步行路线规划失败");
}
}
/// 自定义多路线样式
- (BMKOverlayView*)mapView:(BMKMapView *)map viewForOverlay:(id<BMKOverlay>)overlay {
/// 步行多路线polyline
if ([overlay isKindOfClass:[BMKPolyline class]] && [BMKWalkNavigationManager sharedManager].enableMultiRoute) {
BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
polylineView.lineWidth = 10.0;
if (_isFirstRoute) {
_isFirstRoute = NO;
polylineView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.7];
} else {
polylineView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.4];
}
[_routePolylineViews addObject:polylineView];
return polylineView;
}
return nil;
}
/// 选路
- (void)mapView:(BMKMapView *)mapView onClickedBMKOverlayView:(BMKOverlayView *)overlayView {
if ([overlayView isKindOfClass:[BMKPolylineView class]]) {
BMKOverlayView *polylineView = (BMKOverlayView *)overlayView;
NSInteger idx = [_routePolylines indexOfObject:polylineView.overlay];
if (idx >= 0 && idx < _routePolylines.count) {
// 按照索引路线进行导航引擎算路,算路成功后进入导航
[[BMKWalkNavigationManager sharedManager] naviCalcRoute:idx];
for (int i = 0; i < _routePolylines.count; i++) {
BMKPolylineView *polylineView = _routePolylineViews[i];
if (idx == i) {
polylineView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.7];
} else {
polylineView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.4];
}
}
}
}
_routePolylines = nil;
[_routePolylineViews removeAllObjects];
[self.mapView removeOverlays:self.mapView.overlays];
}
#pragma mark - <BMKWalkNaviCalcRouteDelegate>
/// 引擎算路结果
- (void)onNaviCalcRouteResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType {
if (errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS) {
if (naviType == BMK_WALK_CYCLE_NAVIGATION_TYPE_WALK) {
[[BMKWalkNavigationManager sharedManager] startWalkNaviWithParentController:self isPush:YES];
} else {
[[BMKCycleNavigationManager sharedManager] startCycleNaviWithParentController:self isPush:YES];
}
} else {
NSLog(@"SDK-引擎算路失败 %zd", errorCode);
}
}
监听回调说明

步行导航和骑行导航均使用相同的代理回调,回调中参数 naviType 会告知开发者当前回调是步行导航还是骑行导航,请开发者注意区分。

BMKWalkCycleRoutePlanDelegate

步行导航路线规划代理类,成功后开发者可配合displayRoutePlanResult展示并选择路线进行导航,算路失败发起导航无效。

@optional
/**
开始算路
*/
- (void)onRoutePlanStart:(BMKWalkCycleNavigationType)naviType;
/**
算路结果返回
@param errorCode 错误码
*/
- (void)onRoutePlanResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType;

BMKWalkNaviCalcRouteDelegate

骑行、步行导航算路代理类,其中只有算路结果为成功的情况,开始骑行导航,算路失败发起导航无效。

/// 引擎算路结果
/// @param errorCode 错误码
- (void)onNaviCalcRouteResult:(BMKWalkCycleRoutePlanErrorCode)errorCode;
- (void)onNaviCalcRouteResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType;

BMKWalkCycleManagerDelegate

步行、骑行导航管理代理类,提供退出导航等回调。

BMKWalkCycleRouteGuidanceDelegate

步行、骑行导航诱导信息代理类,提供12个回调方法,主要包括导航开始、结束、导航过程中偏航、偏航结束、诱导信息(包含诱导默认图标、诱导类型、诱导信息、剩余距离、时间、振动回调等)。 详见 BMKWalkCycleNavigationDelegates.h 头文件。

BMKWalkCycleTTSPlayerDelegate

骑行、步行导航TTS语音播报代理类,此组件只提供导航过程中的文本输出,不包含语音播报功能,需要自行传入对应的语音回调,形成播报功能。 建议使用百度语音识别服务SDK。下载地址:

http://yuyin.baidu.com/asr/download

上一篇

骑行导航

下一篇

实时公交查询

本篇文章对您是否有帮助?