/** 启动GPS导航. 前置条件:导航引擎初始化成功 */ private void launchNavigator() { BaiduNaviManager.getInstance() .launchNavigator( this, userLoc.getLatitude(), userLoc.getLongitude(), "我的位置", destLoc.getLatitude(), destLoc.getLongitude(), "终点", NE_RoutePlan_Mode.ROUTE_PLAN_MOD_MIN_TIME, // 算路方式 true, // 真实导航 BaiduNaviManager.STRATEGY_FORCE_ONLINE_PRIORITY, // 在离线策略 new OnStartNavigationListener() { // 跳转监听 @Override public void onJumpToNavigator(Bundle configParams) { Intent intent = new Intent(NavigateActivity.this, BNavigatorActivity.class); intent.putExtras(configParams); startActivity(intent); } @Override public void onJumpToDownloader() {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏 super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.navigate); // 地图初始化 mMapView = (MapView) findViewById(R.id.mapview_navi); mBaiduMap = mMapView.getMap(); mMapView.showZoomControls(false); mMapView.showScaleControl(true); // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); // 开启罗盘 mBaiduMap.getUiSettings().setCompassEnabled(true); // 定位初始化 mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型为百度经纬度坐标 option.setScanSpan(1000); mLocClient.setLocOption(option); mLocClient.start(); mBaiduMap.setOnMapLongClickListener(MyLongClickListener); // 初始化导航引擎 // BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(), // mNaviEngineInitListener,ACCESS_KEY,mKeyVerifyListener); /* BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(), mNaviEngineInitListener, new LBSAuthManagerListener() { @Override public void onAuthResult(int status, String msg) { String str = null; if (0 == status) { str = "key校验成功!"; } else { str = "key校验失败, " + msg; } Toast.makeText(NavigateActivity.this, str, Toast.LENGTH_LONG).show(); } }); */ boolean isInitSuccess = BaiduNaviManager.getInstance().checkEngineStatus(getApplicationContext()); Toast.makeText(NavigateActivity.this, "isInitSuccess" + isInitSuccess, Toast.LENGTH_LONG) .show(); // 设置策略 TextView SetStrategy = (TextView) findViewById(R.id.tvStrategy); SetStrategy.setOnClickListener( new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub showDialog(0); } }); // 规划路径 TextView CalcRoute = (TextView) findViewById(R.id.tvCalcRoutes); CalcRoute.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (hasEndpoint = true) { drivintResultIndex = 0; nextLineBtn.setEnabled(false); drivingSearch(drivintResultIndex); // 驾车路线规划 // startCalcRoute(NL_Net_Mode.NL_Net_Mode_OnLine); } else { Toast.makeText(NavigateActivity.this, "请先设置终点!", Toast.LENGTH_SHORT).show(); } } }); routePlanSearch = RoutePlanSearch.newInstance(); routePlanSearch.setOnGetRoutePlanResultListener(routePlanResultListener); // 开始导航 TextView StartNavigate = (TextView) findViewById(R.id.tvStartNavi); StartNavigate.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // launchNavigator(); startNaviByClient(); // 调用客户端的方式发起导航 } }); // 下一条路径 nextLineBtn = (Button) findViewById(R.id.nextline_btn); nextLineBtn.setEnabled(false); nextLineBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub drivingSearch(++drivintResultIndex); } }); }