1、首先到百度地图开放平台创建应用,获取应用AK
http://lbsyun.baidu.com/apiconsole/key
2、到百度语言平台创建应用,获取Secret Key和语言APP ID
http://yuyin.baidu.com/app
3、到百度地图开放平台下载Android 导航SDK
https://pan.baidu.com/s/1z1cSWmkcE8kHhAXUVL4Ebw
4、修改ak和sk 和APP ID 还有使用你的keystore打包即可完成百度内置导航接入
配置你的ak,sk
配置你的APP ID
配置你的签名
demo 链接:https://pan.baidu.com/s/1z1cSWmkcE8kHhAXUVL4Ebw
密码:在线回复QQ1085220040
在线回复bug.QQ1085220040
运行即可:
2、高德地图内置导航实现——比集成百度内置导航方便,建议使用
申请key:https://lbs.amap.com/
实现demo:https://download.csdn.net/download/meixi_android/12704895
在线bug交流:扣扣1085220040
package com.example.ampnavigation;import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;import com.amap.api.maps.model.Circle;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AMapServiceAreaInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.autonavi.tbt.TrafficFacilityInfo;import java.util.ArrayList;
import java.util.List;public class NaviActivity extends AppCompatActivity {private AMapNaviView mAMapNaviView;private AMapNavi mAMapNavi;protected AlertDialog.Builder builder;protected AlertDialog dialog;private String las,los;private int fwint;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_navi);las = getIntent().getStringExtra("las");los = getIntent().getStringExtra("los");fwint = getIntent().getIntExtra("fw",0);//获取 AMapNaviView 实例mAMapNaviView = findViewById(R.id.navi_view);//获取AMapNavi实例mAMapNavi = AMapNavi.getInstance(getApplicationContext());
// mAMapNavi.setUseInnerVoice(true);mAMapNavi.setUseInnerVoice(true,true);AMapNaviViewOptions options = mAMapNaviView.getViewOptions();//隐藏SDK默认的布局
// options.setLayoutVisible(false);
// options.setTrafficBarEnabled(true);mAMapNaviView.setViewOptions(options);mAMapNavi.setMultipleRouteNaviMode(true);mAMapNaviView.setAMapNaviViewListener(new AMapNaviViewListener() {@Overridepublic void onNaviSetting() {}@Overridepublic void onNaviCancel() {finish();Log.i("lgq","cancel");}@Overridepublic boolean onNaviBackClick() {Log.i("lgq","cancelback");showNavBackDialog();return true;}@Overridepublic void onNaviMapMode(int i) {}@Overridepublic void onNaviTurnClick() {}@Overridepublic void onNextRoadClick() {}@Overridepublic void onScanViewButtonClick() {}@Overridepublic void onLockMap(boolean b) {}@Overridepublic void onNaviViewLoaded() {}@Overridepublic void onMapTypeChanged(int i) {}@Overridepublic void onNaviViewShowMode(int i) {}});mAMapNaviView.onCreate(savedInstanceState);//添加监听回调,用于处理算路成功mAMapNavi.addAMapNaviListener(new AMapNaviListener() {@Overridepublic void onInitNaviFailure() {}@Overridepublic void onInitNaviSuccess() {final double startLatitude = 22.991262;final double startLongitude = 113.707716;final double targetLatitude = 23.001662;final double targetLongitude = 113.607816;//navigate(targetLatitude,targetLongitude);/*** 方法:* int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute);* 参数:* @congestion 躲避拥堵* @avoidhightspeed 不走高速* @cost 避免收费* @hightspeed 高速优先* @multipleroute 多路径** 说明:* 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。* 注意:* 不走高速与高速优先不能同时为true* 高速优先与避免收费不能同时为true*/int strategy = 0;try {strategy = mAMapNavi.strategyConvert(true, false, false, false, false);} catch (Exception e) {e.printStackTrace();}List<NaviLatLng> sList = new ArrayList<NaviLatLng>() {{add(new NaviLatLng(startLatitude, startLongitude));}};List<NaviLatLng> eList = new ArrayList<NaviLatLng>() {{add(new NaviLatLng(targetLatitude, targetLongitude));}};List<NaviLatLng> mWayPointList = null;mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);/*绘制圆*/int alpha = 160;Circle circle = mAMapNaviView.getMap().addCircle(new CircleOptions().center(new LatLng(targetLatitude, targetLongitude)).radius(1000).fillColor(Color.argb(alpha, 10, 200, 1)).fillColor(Color.parseColor("#19999999")).strokeColor(Color.parseColor("#33df6e50")).strokeWidth(10));}@Overridepublic void onStartNavi(int i) {}@Overridepublic void onTrafficStatusUpdate() {}@Overridepublic void onLocationChange(AMapNaviLocation aMapNaviLocation) {}@Overridepublic void onGetNavigationText(int i, String s) {Log.i("lgq","文字啦啦啦 ==== "+s);}@Overridepublic void onGetNavigationText(String s) {Log.i("lgq","文字啦eeee啦啦 ==== "+s);}@Overridepublic void onEndEmulatorNavi() {}@Overridepublic void onArriveDestination() {}@Overridepublic void onCalculateRouteFailure(int i) {}@Overridepublic void onReCalculateRouteForYaw() {}@Overridepublic void onReCalculateRouteForTrafficJam() {}@Overridepublic void onArrivedWayPoint(int i) {}@Overridepublic void onGpsOpenStatus(boolean b) {}@Overridepublic void onNaviInfoUpdate(NaviInfo naviInfo) {}@Overridepublic void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {}@Overridepublic void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {}@Overridepublic void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {}@Overridepublic void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {}@Overridepublic void showCross(AMapNaviCross aMapNaviCross) {}@Overridepublic void hideCross() {}@Overridepublic void showModeCross(AMapModelCross aMapModelCross) {}@Overridepublic void hideModeCross() {}@Overridepublic void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {}@Overridepublic void showLaneInfo(AMapLaneInfo aMapLaneInfo) {}@Overridepublic void hideLaneInfo() {}@Overridepublic void onCalculateRouteSuccess(int[] ints) {mAMapNavi.startNavi(NaviType.GPS);}@Overridepublic void notifyParallelRoad(int i) {}@Overridepublic void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {}@Overridepublic void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {}@Overridepublic void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {}@Overridepublic void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {}@Overridepublic void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {}@Overridepublic void onPlayRing(int i) {}@Overridepublic void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {}@Overridepublic void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) {}@Overridepublic void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {}});Handler handler = new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {mAMapNavi.startSpeak();}}, 500);}@Overrideprotected void onResume() {super.onResume();
// mAMapNavi.startNavi(1);mAMapNaviView.onResume();}@Overrideprotected void onPause() {super.onPause();mAMapNaviView.onPause();}@Overrideprotected void onDestroy() {super.onDestroy();mAMapNaviView.onDestroy();mAMapNavi.destroy();mAMapNavi=null;Log.i("lgqddddddddddddddd","dddddddd33");}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {showNavBackDialog();return true;}return super.onKeyDown(keyCode, event);}/**** 返回按钮 dialog提示*/private void showNavBackDialog() {builder = new AlertDialog.Builder(this);builder.setTitle("提示");builder.setMessage("确定退出导航?");builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {}});builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {finish();}});dialog = builder.show();}/**** 回收dialog*/private void dismissDialog(){if(dialog != null){if(dialog.isShowing()){dialog.dismiss();}dialog = null;}builder = null;}
}