{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671516319752,"data":{"id":71712908,"title":"5.3.3.4 重算信息设置","slug":"mgs8a2","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"
重算分为主动重算和被动重算两种,被动重算又分为偏航重算以及静默重算两种,不同类型的重算优先级不一样。
AutoSDK内部会默认执行优先级管理策略(外部无法调整):客户端首次发起算路请求后,在未收到算路应答前,如果又发起一次新的算路请求,会触发优先级管理策略。具体规则如下:
具体重算类型以及优先级说明如下:
用户主动重算,优先级为1(最高),具体如下算路类型:
com.autonavi.gbl.common.path.option.RouteType.RouteTypeCommon: //1 普通算路\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeChangeStratege: //3 切换策略\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeParallelRoute: //4 平行路切换\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeChangeJnyPnt: //9 停车场模式/沿途搜索设置行程点\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeManualRefresh: //12 手动刷新\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeAvoid: //15 骑行导航中请求避让路线\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeDispatch: //16 交警调度请求路线\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeVoiceChangeDest: //17 语音更换目的地\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeSwitchMode: //21 导航中驾驶模式切换(在线电动车专用)\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeVoiceAddViaPoint: //23 语音追加途经点\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeGroupChangeDest: //26 导航中更换目的地
用户被动重算,优先级相对较低,分为【偏航重算】和【静默重算】:
com.autonavi.gbl.common.path.option.RouteType.RouteTypeYawRoute: //2 偏航重算
com.autonavi.gbl.common.path.option.RouteType.RouteTypeTMC: //5 tmc引起的重算\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeLimitLine: \t\t//6 道路限行 (车牌限行)\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeDamagedRoad: //7 道路关闭\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeUpdateCityData: //10 更新城市数据引起的重算\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeLimitForbid: //11 限时禁行引起的重算(在线)\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeLimitForbidOffLine: //13 限时禁行引起的重算(本地)\ncom.autonavi.gbl.common.path.option.RouteType.RouteTypeMutiRouteRequest: //14 导航中请求备选路线
特别需要注意SetNaviPath接口在500之后(包括500)的变更,老版本接口使用详情如下:
500之前的版本,备选路重算的结果,算路结果只返回备选路线,HMI需要保留旧的主引导路线,并且将onNewRoute下发的新路线结果(里面只有备选路线)通过GuideService.setNaviPath( naviPath, -1)设置给GuideService。【这种setNaviPath传入-1的用法已废弃】
void com.autonavi.gbl.guide.observer.INaviObserver.onReroute(RouteOption rerouteOption)
void com.autonavi.gbl.common.path.option.copy (RouteOption src)
int com.autonavi.gbl.common.path.option.RouteOption.getRouteType()
boolean com.autonavi.gbl.common.path.option.RouteOption.setPOIForRequest (POIForRequest points)
boolean com.autonavi.gbl.common.path.option.RouteOption.setCurrentLocation (CurrentPositionInfo posInfo)
long com.autonavi.gbl.route.RouteService.requestRoute (RouteOption routeOption)
void com.autonavi.gbl.route.observer.IRouteResultObserver.onNewRoute(PathResultData pathResultData,ArrayList<PathInfo> pathInfoList,java.lang.Object externData)\t
boolean com.autonavi.gbl.guide.GuideService.setNaviPath (NaviPath naviPath, int mainIndex)
void com.autonavi.gbl.layer.BizGuideRouteControl.setPathInfos(ArrayList<BizPathInfoAttrs> pathInfo, int selectIndex)
void com.autonavi.gbl.layer.BizGuideRouteControl.updatePaths()
RouteOption详细参数见【基础算路】
说明:函数详情,请复制函数名称到在线API搜索
// 初始化设置route\nprivate void initRoute() {\n\tmRouteService = (RouteService) ServiceMgr.getServiceMgrInstance().getBLService(SingleServiceID.RouteSingleServiceID);\n\troute = mRouteService.init();\n\t\n\tmRouteService.control(RouteControlKey.RouteControlKeyVehicleID, "车牌号***"); //设置车牌\n\tmRouteService.control(RouteControlKey.RouteControlKeySetMutilRoute, "1");// 开启多路线规划\n //todo:其它必要的设置,按功能设置\n mRouteService.control(***) \n\n\tmRouteService.add***Observer(***); //注册观察者\n}\n\n// 初始化设置guide\nprivate void initGuide() {\n mGuideService = (GuideService) ServiceMgr.getServiceMgrInstance().getBLService(SingleServiceID.GuideSingleServiceID);\n guide = mGuideService.init();\n \t\n //基础navi参数设置\n Param param = new Param();\n param.type = GuideParamNavi;\n param.navi.naviScene = 0; //普通导航\n param.navi.model = 1; // 多路线导航(备选路重算需要开启)\n mGuideService.setParam(param);\n // todo : 其它Param设置\n // ...\n \n mGuideService.add***Observer(***); //注册观察者\n}\n\n// onReroute重算回调\nINaviObserver INaviObserver = new INaviObserver(){\n\t@Override\n\tpublic void onReroute(RouteOption rerouteOption) {\n RouteOption routeOption = RouteOption.create();\n\t\trouteOption.copy(rerouteOption);//深拷贝\n\n\t\t// 设置算路参数,根据需求情况赋值\n // 0x40 代表算路时考虑高速优先\n // 0x2000 代表有网络\n // 0x04 代表启用备选路径,备选路径一般是3条,但有可能存在相同路径,默认排除重复路径,如希望保留重复路径,组合不排除重复路径标志位\n // 0x8 代表弃用路径重排\n\t\trouteOption.setConstrainCode(0x40|0x2000|0x04|0x08); \n\t\t// 重算时需要再次设置算路策略,算路策略根据偏好设置,一般为上一次客户端设置的路线偏好\n\t\troutOption.setRouteStrategy(lastRouteStrategy);\n \n\t\t// 重算原因\n int routeType = routeOption.getRouteType();\n\t\tswitch(routeType){\n\t\t \t//6 道路限行\n\t\t case RouteTypeLimitLine:\n\t\t //7 道路关闭\n\t\t case RouteTypeDamagedRoad:\n\t\t //10 更新城市数据引起的重算\n\t\t case RouteTypeUpdateCityData:\n //手动刷新\n case RouteTypeManualRefresh:\n // 语音更换目的地\n case RouteTypeVoiceChangeDest:\n //导航中驾驶模式切换(在线电动车专用)\n case RouteTypeSwitchMode:\n //语音追加途经点\n case RouteTypeVoiceAddViaPoint:\n {\n // 获取算路行程点\n\t\t\t\tPOIForRequest poiForRequest = routeOption.getPOIForRequest();\n\t\t\t\t// 获取最新的定位信息,更新以下行程点信息\n\t\t\t\tLocInfo locInfo = POS模块当前位置回调;\n // 更新行程点。调用AddPoint或ClearPoint。\n poiForRequest.更新起点;//一般来源当前定位回调信息locInfo\n poiForRequest.更新终点;//如果有变才改\n poiForRequest.更新途径点;//要删除已经失效点途径点\n\n \t\t// 起点抓路优化\n\t\t\t\tpoiForRequest.setDirection(locInfo.matchRoadCourse);\n\t\t\t\tpoiForRequest.setReliability(locInfo.courseAcc);\n\t\t\t\tpoiForRequest.setAngleType(locInfo.startDirType);\n\t\t\t\tpoiForRequest.setAngleGps(locInfo.gpsDir);\n\t\t\t\tpoiForRequest.setAngleComp(locInfo.compassDir);\n\t\t\t\tpoiForRequest.setSpeed(locInfo.speed);\n\t\t\t\tpoiForRequest.setLinkType(locInfo.matchInfo[0].linkType);\n\t\t\t\tpoiForRequest.setFormWay(locInfo.matchInfo[0].formway);\n\t\t\t\tpoiForRequest.setSigType(locInfo.startPosType);\n\t\t\t\tpoiForRequest.setFittingDir(locInfo.fittingCourse);\n\t\t\t\tpoiForRequest.setMatchingDir(locInfo.roadDir);\n\t\t\t\tpoiForRequest.setFittingCredit(locInfo.fittingCourseAcc);\n\t\t\t\tpoiForRequest.setPrecision(locInfo.posAcc);\n // 设置行程点信息\n\t\t\t\trouteOption.setPOIForRequest(poiForRequest);\n \n\t\t\t\t// 当前位置信息\n\t\t\t\tCurrentPositionInfo positionInfo = routeOption.getCurrentLocation();\n\t\t\t\tpositionInfo.segmentIndex = locInfo.matchInfo[0].segmCur;\n\t\t\t\tpositionInfo.linkIndex = locInfo.matchInfo[0].linkCur;\n\t\t\t\tpositionInfo.pointIndex = locInfo.matchInfo[0].postCur;\n\t\t\t\tpositionInfo.overheadFlag = 0;\n\t\t\t\tpositionInfo.parallelRoadFlag = 0;\n // 设置当前导航位置信息\n\t\t routeOption.setCurrentLocation(positionInfo);\n\t\t break;\n\t\t }\n\t\t //偏航重算\n\t\t \tcase RouteTypeYaw:\n\t\t //5 tmc引起的重算\n\t\t case RouteTypeTMC:\n\t\t //11 限时禁行引起的重算(在线)\n\t\t case RouteTypeLimitForbid:\n\t\t //13 限时禁行引起的重算(在线) \n\t\t case RouteTypeLimitForbidOffLine:\n\t\t //14 导航中请求备选路线\n\t\t case RouteTypeMutiRouteRequest:\n // 不需要重新设置行程点信息\n \n\t\t break;\n\t\t default:\n\t\t break;\n\t\t}\n \n\t\t// 如是新能源汽车,需要设置电量\n\t\trouteOption.setVehicleCharge(200.0f);\n\t // todo:其它设置\n\t // ...\n \n\t // 发起请求\n\t\tmRouteService.requestRoute(routeOption);\n \n // 内存释放\n RouteOption.destroy(routeOption);\n\t}\n \n // other impl\n // ...\n}\n\n// 重算后算路结果观察者\nIRouteResultObserver routeResultObserver = new IRouteResultObserver() {\n @Override\n public void onNewRoute(PathResultData pathResultData, ArrayList<PathInfo> pathInfoList, java.lang.Object externData) {\n \n /* 转UI线程前,这边需要特殊处理。对SDK回调回来的PathInfo对象需重新构造创建一遍 */\n ArrayList<PathInfo> paths = new ArrayList<>();\n for(int i=0;i<pathInfoList.size();i++){\n PathInfo paths =new PathInfo(pathInfoList.get(i));\n paths.add(pathInfo);\n }\n // 根据情况决定是否将后续处理流程转为其他线程处理,如果转线程,只需将下面示例中的HandleNewRoute函数放在指定线程执行即可\n HandleNewRoute(pathResultData, paths);\n }\n\n @Override\n public void onNewRouteError(PathResultData pathResultData, java.lang.Object externData) {\n if (pathResultData.type == RouteTypeMutiRouteRequest && pathResultData.errorCode == RouteErrorcodeUnkonw)\n {\n // 备选路重算 失败错误码13 不处理\n }\n else \n {\n // 其它对应的处理逻辑\n }\n }\n};\n\n/* UI线程逻辑 */\nvoid HandleNewRoute(PathResultData pathResultData, ArrayList<PathInfo> paths)\n{\n PathsMgr.getInstance().setPathsCache(paths);\n \n // 设置给图层显示:\n // 注意事项:给图层的数据需要完整的路线数据(主路线+备选路线)\n // pathResultData中,如果是备选路重算结果,需要把上一次的主路线加进去设置给图层。\n // 具体图层设置接口如下\n // 添加路线数据给图层:BizGuideRouteControl.setPathInfos \n // 触发图层的路线更新:BizGuideRouteControl.updatePaths\n // ...\n \n // 导航路线信息\n NaviPath naviPath = new NaviPath();\n // 导航路线\n naviPath.setVecPaths(PathsMgr.getInstance().getPathsCache());\n // 设置行程点信息。用于偏航时组织终点信息, 不影响路线绘制,来源HMI记录的最近一次算路请求的行程点信息\n naviPath.setPoint(poiForRequest);\n // 算路策略,可组合,0x00:无策略,0x01:避免收费,0x02:不走高速,0x04:高速优先,0x08:躲避拥堵,0F:大于此值认为数据无效,当做无策略处理\n naviPath.setStrategy(0x00);\n\n // 设置路线的算路类型\n if (RouteType.RouteTypeAosRoute == pathResultData.type ||RouteType.RouteTypeRestoration == pathResultData.type)\n {\n naviPath.setType(RouteType.RouteTypeCommon);//路线还原使用RouteTypeCommon\n }\n else\n {\n naviPath.setType(pathResultData.type);\n }\n \n // 设置路线场景\n // scene,来源当前HMI的场景记录\n if (服务区续航场景 == scene)\n {\n naviPath.setScene(SceneFlagType.SceneFlagTypeServiceAreaContinuation);\n }\n if (普通续航场景 == scene)\n {\n naviPath.setScene(SceneFlagType.SceneFlagTypeOrdinaryContinuation);\n }\n if (导航结束页场景 == scene)\n {\n naviPath.setScene(SceneFlagType.SceneFlagTypeNormal);\n }\n \n // 设置路线给引导服务\n if (RouteType.RouteTypeMutiRouteRequest == pathResultData.type)\n {\n getGuideService().setNaviPath(naviPath, -1); //备选路,设置-1\n }\n else\n {\n getGuideService().setNaviPath(naviPath, 0); //其它的重算,需要设置正确的主路线,可以由用户交互选择,也可以是默认0\n }\n \n // 若之后业务还需使用路线 通过getPathsCache获取\n // 若业务执行到不再当次路线结果时回收路线 destoryPathsCache()\n \n};\n\n\npublic class PathsMgr {\n public static final String TAG = "PathsMgr";\n private ArrayList<PathInfo> mPathsCache;\n \n private static class SinglonHolder {\n private static PathsMgr instance = new PathsMgr();\n }\n\n public static PathsMgr getInstance() {\n return SinglonHolder.instance;\n }\n\n // 在UI线程缓存路线结果\n public void setPathsCache(ArrayList<PathInfo> paths) {\n // 清除上一次老路线缓存\n destoryPathsCache()\n //无效的结果不需要cache\n if (paths == null || paths.size() <= 0) {\n return;\n }\n mPathsCache = paths;\n Logger.d(TAG,"setPathsCache:paths = {?}",paths.toString());\n }\n \n // 在UI线程获取路线缓存结果\n public ArrayList<PathInfo> getPathsCache() {\n Logger.d(TAG,"getPathsCache:paths = {?}",mPathsCache.toString());\n return mPathsCache;\n }\n\n // 不再使用当前路线时在UI线程调用,如退出路线规划页,结束真实导航\n public void destoryPathsCache() {\n if (mPathsCache == null || mPathsCache.size() <= 0) {\n return;\n }\n Iterator<PathInfo> it = mPathsCache.iterator();\n while(it.hasNext()){\n PathInfo pathInfo = it.next();\n pathInfo.delete();\n it.remove();\n }\n }\n}
图层关于路径线部分的内容请参考【路线绘制】