国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

關于基礎百度地圖和地圖導航的bug問題

2019-11-08 00:26:05
字體:
來源:轉載
供稿:網友

這個情況出現在項目開發中的bug,就是百度地圖開發中的基礎地圖和地圖導航,在正常情況下,基礎地圖應該在地圖導航之前(因為百度基礎地圖和導航是分開的),先說一下自己的bug問題,因為在項目中有不同入口可以進入導航那個模塊,所以也就出現可能,用戶在沒有使用基礎地圖之前就導航,會崩潰,所以為了避免這個問題的出現,最好在app開啟的時候就先拿到BaiduMap對象,百度會自動創建對象,之后就不用擔心基礎地圖未創建就進行導航了。地圖導航那個界面就官網上有,直接復制就可以使用,只要傳入起點和終點坐標就可以了。下面是導航界面的完成代碼,原封不動,配置好ak和拿到tts白名單之后,放好架包和so文件,就能正常導航了

public class BNDemoGuideActivity extends Activity {   PRivate final String TAG = BNDemoGuideActivity.class.getName();   private BNRoutePlanNode mBNRoutePlanNode = null;   private BaiduNaviCommonModule mBaiduNaviCommonModule = null;   /*     * 對于導航模塊有兩種方式來實現發起導航。 1:使用通用接口來實現 2:使用傳統接口來實現     *     */   // 是否使用通用接口   private boolean useCommonInterface = true;   @Override   protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      createHandler();      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {      }      View view = null;      if (useCommonInterface) {         //使用通用接口         mBaiduNaviCommonModule = NaviModuleFactory.getNaviModuleManager().getNaviCommonModule(               NaviModuleImpl.BNaviCommonModuleConstants.ROUTE_GUIDE_MODULE, this,               BNaviBaseCallbackModel.BNaviBaseCallbackConstants.CALLBACK_ROUTEGUIDE_TYPE, mOnNavigationListener);         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onCreate();            view = mBaiduNaviCommonModule.getView();         }      } else {         //使用傳統接口         view = BNRouteGuideManager.getInstance().onCreate(this,mOnNavigationListener);      }      if (view != null) {         setContentView(view);      }      Intent intent = getIntent();      if (intent != null) {         Bundle bundle = intent.getExtras();         if (bundle != null) {            mBNRoutePlanNode = (BNRoutePlanNode) bundle.getSerializable(ParkInformationActivity.ROUTE_PLAN_NODE);         }      }      //顯示自定義圖標      if (hd != null) {         hd.sendEmptyMessageAtTime(MSG_SHOW, 5000);      }   }   @Override   protected void onResume() {      super.onResume();      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onResume();         }      } else {         BNRouteGuideManager.getInstance().onResume();      }   }   protected void onPause() {      super.onPause();      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onPause();         }      } else {         BNRouteGuideManager.getInstance().onPause();      }   };   @Override   protected void onDestroy() {      super.onDestroy();      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onDestroy();         }      } else {         BNRouteGuideManager.getInstance().onDestroy();      }   }   @Override   protected void onStop() {      super.onStop();      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onStop();         }      } else {         BNRouteGuideManager.getInstance().onStop();      }   }   @Override   public void onBackPressed() {      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onBackPressed(false);         }      } else {         BNRouteGuideManager.getInstance().onBackPressed(false);      }   }   public void onConfigurationChanged(android.content.res.Configuration newConfig) {      super.onConfigurationChanged(newConfig);      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onConfigurationChanged(newConfig);         }      } else {         BNRouteGuideManager.getInstance().onConfigurationChanged(newConfig);      }   };   @Override   public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            Bundle mBundle = new Bundle();            mBundle.putInt(RouteGuideModuleConstants.KEY_TYPE_KEYCODE, keyCode);            mBundle.putParcelable(RouteGuideModuleConstants.KEY_TYPE_EVENT, event);            mBaiduNaviCommonModule.setModuleParams(RouteGuideModuleConstants.METHOD_TYPE_ON_KEY_DOWN, mBundle);            try {               Boolean ret = (Boolean)mBundle.get(RET_COMMON_MODULE);               if(ret) {                  return true;               }            }catch(Exception e){               e.printStackTrace();            }         }      }      return super.onKeyDown(keyCode, event);   }   @Override   protected void onStart() {      super.onStart();      // TODO Auto-generated method stub      if(useCommonInterface) {         if(mBaiduNaviCommonModule != null) {            mBaiduNaviCommonModule.onStart();         }      } else {         BNRouteGuideManager.getInstance().onStart();      }   }   private void addCustomizedLayerItems() {      List<CustomizedLayerItem> items = new ArrayList<CustomizedLayerItem>();      CustomizedLayerItem item1 = null;      if (mBNRoutePlanNode != null) {         item1 = new CustomizedLayerItem(mBNRoutePlanNode.getLongitude(), mBNRoutePlanNode.getLatitude(),               mBNRoutePlanNode.getCoordinateType(), getResources().getDrawable(R.drawable.app_logo),               CustomizedLayerItem.ALIGN_CENTER);         items.add(item1);         BNRouteGuideManager.getInstance().setCustomizedLayerItems(items);      }      BNRouteGuideManager.getInstance().showCustomizedLayer(true);   }   private static final int MSG_SHOW = 1;   private static final int MSG_HIDE = 2;   private static final int MSG_RESET_NODE = 3;   private Handler hd = null;   private void createHandler() {      if (hd == null) {         hd = new Handler(getMainLooper()) {            public void handleMessage(android.os.Message msg) {               if (msg.what == MSG_SHOW) {                  addCustomizedLayerItems();               } else if (msg.what == MSG_HIDE) {                  BNRouteGuideManager.getInstance().showCustomizedLayer(false);               } else if (msg.what == MSG_RESET_NODE) {                  BNRouteGuideManager.getInstance().resetEndNodeInNavi(                        new BNRoutePlanNode(116.21142, 40.85087, "百度大廈11", null, CoordinateType.GCJ02));               }            };         };      }   }   private OnNavigationListener mOnNavigationListener = new OnNavigationListener() {      @Override      public void onNaviGuideEnd() {         //退出導航         finish();      }      @Override      public void notifyOtherAction(int actionType, int arg1, int arg2, Object obj) {         if (actionType == 0) {            //導航到達目的地 自動退出            Log.i(TAG, "notifyOtherAction actionType = " + actionType + ",導航到達目的地!");         }         Log.i(TAG, "actionType:" + actionType + "arg1:" + arg1 + "arg2:" + arg2 + "obj:" + obj.toString());      }   };   private final static String RET_COMMON_MODULE = "module.ret";   private interface RouteGuideModuleConstants {      final static int METHOD_TYPE_ON_KEY_DOWN = 0x01;      final static String KEY_TYPE_KEYCODE = "keyCode";      final static String KEY_TYPE_EVENT = "event";   }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上虞市| 思南县| 瑞丽市| 定安县| 西藏| 茂名市| 稷山县| 咸宁市| 西华县| 昌图县| 江津市| 嘉善县| 盘锦市| 镇康县| 温宿县| 舞钢市| 高台县| 桐梓县| 新郑市| 磐石市| 宝清县| 个旧市| 奉化市| 秀山| 贵德县| 中阳县| 保亭| 淮北市| 漳州市| 通化市| 重庆市| 宁河县| 新宁县| 金塔县| 大同市| 临清市| 永丰县| 阿勒泰市| 怀仁县| 马边| 象山县|