在使用百度导航SDK任何功能之前,前需要先进行初始化,初始化方法是调用如下接口:
/*** 初始化百度导航.** @param context 建议是应用的context* @param sdcardRootPath 系统SD卡根目录路径* @param naviInitListener 百度导航初始化监听器*/BNaviInitConfig config = new BNaviInitConfig.Builder().sdcardRootPath(sdcardRootPath).naviInitListener(new IBaiduNaviManager.INaviInitListener()).build();BaiduNaviManagerFactory.getBaiduNaviManager().init(context, config);
interface INaviInitListener {/*** 授权校验结果** @param status 0 表示成功,其他表示失败* @param msg 具体授权校验失败信息*/void onAuthResult(int status, String msg);/*** 百度导航初始化开始*/void initStart();/*** 百度导航初始化成功*/void initSuccess();/*** 百度导航初始化失败*/void initFailed(int errorCode);}
BNRoutePlanNode sNode = new BNRoutePlanNode.Builder().latitude(40.05087).longitude(116.30142).name("百度大厦").description("百度大厦").coordinateType(CoordinateType.GCJ02).build();BNRoutePlanNode eNode = new BNRoutePlanNode.Builder().latitude(39.90882).longitude(116.39750).name("北京天安门").description("北京天安门").coordinateType(CoordinateType.GCJ02).build();List<BNRoutePlanNode> list = new ArrayList<>();list.add(sNode);list.add(eNode);BaiduNaviManagerFactory.getRoutePlanManager().routePlan(list,IBNRoutePlanManager.RoutePlanPreference.ROUTE_PLAN_PREFERENCE_DEFAULT,null, new Handler(Looper.getMainLooper()) {@Overridepublic void handleMessage(Message msg) {switch (msg.what) {case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_START:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路开始", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_SUCCESS:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路成功", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_FAILED:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路失败", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_TO_NAVI:Toast.makeText(DemoMainActivity.this.getApplicationContext(),"算路成功准备进入导航", Toast.LENGTH_SHORT).show();Intent intent = new Intent(DemoMainActivity.this,DemoGuideActivity.class);startActivity(intent);break;default:// nothingbreak;}}});
上一篇
下一篇
本篇文章对您是否有帮助?