在使用百度导航sdk任何功能之前,前需要先进行初始化,初始化方法是调用如下接口:
/*** 初始化百度导航.** @param context 建议是应用的context* @param sdcardrootpath 系统sd卡根目录路径* @param appfoldername 应用在sd卡中的目录名* @param naviinitlistener 百度导航初始化监听器*/bnaviinitconfig config =newbnaviinitconfig.builder().sdcardrootpath(sdcardrootpath).appfoldername(appfoldername).naviinitlistener(newibaidunavimanager.inaviinitlistener()).build();baidunavimanagerfactory.getbaidunavimanager().init(context, config);
interfaceinaviinitlistener{/*** 授权校验结果** @param status 0 表示成功,其他表示失败* @param msg 具体授权校验失败信息*/voidonauthresult(int status,string msg);/*** 百度导航初始化开始*/voidinitstart();/*** 百度导航初始化成功*/voidinitsuccess();/*** 百度导航初始化失败*/voidinitfailed(int errorcode);}
bnrouteplannode snode =newbnrouteplannode.builder().latitude(40.05087).longitude(116.30142).name("百度大厦").description("百度大厦").coordinatetype(coordinatetype.gcj02).build();bnrouteplannode enode =newbnrouteplannode.builder().latitude(39.90882).longitude(116.39750).name("北京天安门").description("北京天安门").coordinatetype(coordinatetype.gcj02).build();list<bnrouteplannode> list =newarraylist<>();list.add(snode);list.add(enode);baidunavimanagerfactory.getrouteplanmanager().routeplantonavi(list,ibnrouteplanmanager.routeplanpreference.route_plan_preference_default,null,newhandler(looper.getmainlooper()){@overridepublicvoidhandlemessage(message msg){switch(msg.what){caseibnrouteplanmanager.msg_navi_route_plan_start:toast.maketext(demomainactivity.this.getapplicationcontext(),"算路开始",toast.length_short).show();break;caseibnrouteplanmanager.msg_navi_route_plan_success:toast.maketext(demomainactivity.this.getapplicationcontext(),"算路成功",toast.length_short).show();break;caseibnrouteplanmanager.msg_navi_route_plan_failed:toast.maketext(demomainactivity.this.getapplicationcontext(),"算路失败",toast.length_short).show();break;caseibnrouteplanmanager.msg_navi_route_plan_to_navi:toast.maketext(demomainactivity.this.getapplicationcontext(),"算路成功准备进入导航",toast.length_short).show();intent intent =newintent(demomainactivity.this,demoguideactivity.class);startactivity(intent);break;default:// nothingbreak;}}});
上一篇
下一篇
本篇文章对您是否有帮助?