{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508849520,"data":{"id":71714067,"title":"5.3.7 行中SDK自动发起被动重算","slug":"ao4qsg","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"

场景图

重算分为主动重算和被动重算两种,被动重算又分为偏航重算以及静默重算两种,不同类型的重算优先级不一样

考虑到过往SDK项目对接时,许多客户在行中被动重算的对接环节,经常出现错误,SDK在>=610版本,提供了“行中SDK自动发起被动重算”功能,SDK自动接管所有的被动重算,不包含主动重算。区别于以往的HMI接管被动重算。需要注意的是,SDK提供的“行中SDK自动发起被动重算”功能,有开关可选,开关见下方时序图和核心接口说明。HMI可根据自身业务需求,选择使用SDK的“行中SDK自动发起被动重算”,或者沿用之前的业务时序,HMI自行接管被动重算。

被动重算的定义,请参考文档《重算信息设置》

特别注意:对接了多屏一致性的项目,不可使用此功能,,强行开启是无效的,请严格按照文档时序进行实现:《算路一致性》

时序图

服务管理初始化

定位服务初始化

TBT服务初始化

图层服务初始化

路径演算

开始导航


为了方便开发者了解开关“行中SDK自动发起被动重算”的区别,在此列出功能关闭&开启的时序图对比。

核心接口

void com.autonavi.gbl.route.RouteService.init(RouteInitParam param)
void com.autonavi.gbl.route.RouteService.addRerouteObserver(INaviRerouteObserver ob)
void com.autonavi.gbl.route.RouteService.removeRerouteObserver(INaviRerouteObserver ob)
void com.autonavi.gbl.guide.observer.INaviObserver.onReroute(RouteOption rerouteOption)
void com.autonavi.gbl.route.observer.INaviRerouteObserver.onRerouteInfo(BLRerouteRequestInfo info);
void com.autonavi.gbl.route.observer.INaviRerouteObserver.onModifyRerouteOption(RouteOption rerouteOption);
boolean com.autonavi.gbl.common.path.option.RouteOption.setPOIForRequest (POIForRequest points)
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\tRouteInitParam routeInitParam;\n    routeInitParam.rerouteParam.enableAutoReroute = True;\n    mRouteService.init(routeInitParam);\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    mRouteService.addRerouteObserver(naviRerouteObserver);\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// 行中重算回调观察者\nINaviRerouteObserver naviRerouteObserver = new INaviRerouteObserver(){\n    @Override\n    public void OnRerouteInfo(BLRerouteRequestInfo info) {\n        // 此接口用于SDK向HMI通知发起的算路信息。\n        long requestId = info.getRequestId(); // 算路请求requestId\n        int errCode = info.getErrCode(); // 算路请求错误码\n        RouteOption option = info.getOption(); // 算路请求参数\n    }  \n    \n    @Override\n    public void onModifyRerouteOption(RouteOption rerouteOption) {\n        // HMI 可在这个回调线程中,根据自身业务需要,修改rerouteOption\n        // 起点终点:不建议客户端在此回调中修改算路起点&终点,容易改成问题,BL已内聚处理。\n        // 途经点:HMI可根据自身业务需要进行途经点的增删,如无特殊业务需要,建议不改。\n        \n        // 特别注意:只有在当前回调线程中修改参数才会生效,转线程修改无效!\n        \n        // 举例:如有需要修改算路参数                \n        rerouteOption.setConstrainCode(...);       \n        \n        // 举例:HMI如不希望发起本次算路\n        rerouteOption.setAutoRerouteCancel(True);\n    }      \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}


注意事项

图层关于路径线部分的内容请参考【路线绘制

","body_lake":null,"pub_level":null,"status":"0","updated_at":"2022-05-27 10:15:30","deleted_at":null,"nameSpace":"mnlcaa/v610","browseCount":155,"collectCount":0,"estimateDate":23,"docStatus":0,"permissions":true,"overView":false}}