Android百度地圖導航的那些坑
阿新 • • 發佈:2019-02-11
public class NaviBdMapActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 建立NmapView
if (Build.VERSION.SDK_INT < 14) {
BaiduNaviManager.getInstance().destroyNMapView();
}
MapGLSurfaceView nMapView = BaiduNaviManager.getInstance().createNMapView(this );
// 建立導航檢視
View navigatorView = BNavigator.getInstance().init(
NaviBdMapActivity.this, getIntent().getExtras(),
nMapView);
// 填充檢視
setContentView(navigatorView);
BNavigator.getInstance().setListener(mBNavigatorListener);
BNavigator.getInstance().startNav();
// 初始化TTS. 開發者也可以使用獨立TTS模組,不用使用導航SDK提供的TTS
BNTTSPlayer.initPlayer();
// 設定TTS播放回調
BNavigatorTTSPlayer.setTTSPlayerListener(new IBNTTSPlayerListener() {
@Override
public int playTTSText(String arg0, int arg1) {
// 開發者可以使用其他TTS的API
return BNTTSPlayer.playTTSText(arg0, arg1);
}
@Override
public void phoneHangUp() {
// 手機結束通話
}
@Override
public void phoneCalling() {
// 通話中
}
@Override
public int getTTSState() {
// 開發者可以使用其他TTS的API,
return BNTTSPlayer.getTTSState();
}
});
BNRoutePlaner.getInstance().setObserver(
new RoutePlanObserver(this, new IJumpToDownloadListener() {
@Override
public void onJumpToDownloadOfflineData() {
}
}));
}
private IBNavigatorListener mBNavigatorListener = new IBNavigatorListener() {
@Override
public void onYawingRequestSuccess() {
// TODO 偏航請求成功
}
@Override
public void onYawingRequestStart() {
// TODO 開始偏航請求
}
@Override
public void onPageJump(int jumpTiming, Object arg) {
// TODO 頁面跳轉回調
if (IBNavigatorListener.PAGE_JUMP_WHEN_GUIDE_END == jumpTiming) {
finishActivity();
} else if (IBNavigatorListener.PAGE_JUMP_WHEN_ROUTE_PLAN_FAIL == jumpTiming) {
finishActivity();
}
}
@Override
public void notifyGPSStatusData(int arg0) {
}
@Override
public void notifyLoacteData(LocData arg0) {
}
@Override
public void notifyNmeaData(String arg0) {
}
@Override
public void notifySensorData(SensorData arg0) {
}
@Override
public void notifyStartNav() {
BaiduNaviManager.getInstance().dismissWaitProgressDialog();
}
@Override
public void notifyViewModeChanged(int arg0) {
}
};
@Override
public void onResume() {
BNavigator.getInstance().resume();
super.onResume();
BNMapController.getInstance().onResume();
};
@Override
public void onPause() {
BNavigator.getInstance().pause();
super.onPause();
BNMapController.getInstance().onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
BNavigator.getInstance().onConfigurationChanged(newConfig);
super.onConfigurationChanged(newConfig);
}
public void onBackPressed() {
BNavigator.getInstance().onBackPressed();
}
@Override
public void onDestroy() {
BNavigator.destory();
BNRoutePlaner.getInstance().setObserver(null);
super.onDestroy();
}
public void finishActivity() {
finish();
overridePendingTransition(R.anim.in_from_right,R.anim.out_to_left);
}
}