高德導(dǎo)航sdk版本7.6.0
1.起終點(diǎn)算路,手動(dòng)開啟導(dǎo)航:
//poiList為途經(jīng)點(diǎn)易核,起始點(diǎn)和途經(jīng)點(diǎn)可以為null匈织,起始點(diǎn)為null時(shí)已當(dāng)前位置為起始點(diǎn)導(dǎo)航
//第四個(gè)參數(shù)為通行方式(步行、駕車等)
AmapNaviParams params =new AmapNaviParams(new Poi("起始點(diǎn)", startLatlng, ""), poiList, new Poi("結(jié)束點(diǎn)", endLatlng, ""), AmapNaviType.DRIVER);
//開啟語音提示
params.setUseInnerVoice(true);
//第三個(gè)參數(shù)為回調(diào)接口
AmapNaviPage.getInstance().showRouteActivity(getApplicationContext(), params, callback);
2.起終點(diǎn)算路,自動(dòng)開啟導(dǎo)航:
//與上面的方式大同小異缀匕,調(diào)用AmapNaviParams的重載方法纳决,最后的參數(shù)為AmapPageType.Navi硫狞。
AmapNaviParams amapNaviParams = new AmapNaviParams(start, poiList, end, AmapNaviType.DRIVER, AmapPageType.NAVI);
3.不同通行方式的導(dǎo)航
首先在布局內(nèi)添加導(dǎo)航的地圖
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.amap.api.navi.AMapNaviView
android:id="@+id/navi_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
設(shè)置路徑規(guī)劃策略滓鸠,開始計(jì)算導(dǎo)航路徑
//初始化完成
@Override
public void onInitNaviSuccess() {
super.onInitNaviSuccess();
/**
* 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 參數(shù):
*
* @congestion 躲避擁堵
* @avoidhightspeed 不走高速
* @cost 避免收費(fèi)
* @hightspeed 高速優(yōu)先
* @multipleroute 多路徑
*
* 說明: 以上參數(shù)都是boolean類型,其中multipleroute參數(shù)表示是否多條路線秸仙,如果為true則此策略會(huì)算出多條路線满钟。
* 注意: 不走高速與高速優(yōu)先不能同時(shí)為true 高速優(yōu)先與避免收費(fèi)不能同時(shí)為true
*/
int strategy = 0;
try {
//再次強(qiáng)調(diào)胜榔,最后一個(gè)參數(shù)為true時(shí)代表多路徑,否則代表單路徑
strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
} catch (Exception e) {
e.printStackTrace();
}
//駕車路徑規(guī)劃
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
//步行路徑規(guī)劃
mAMapNavi.calculateWalkRoute(new NaviLatLng(39.925846, 116.435765), new NaviLatLng(39.925846, 116.532765));
//騎行路徑規(guī)劃
mAMapNavi.calculateRideRoute(new NaviLatLng(39.925846, 116.435765), new NaviLatLng(39.925846, 116.532765));
}
//計(jì)算線路完成開始導(dǎo)航
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
super.onCalculateRouteSuccess(aMapCalcRouteResult);
mAMapNavi.startNavi(NaviType.GPS);
}
4.導(dǎo)航UI自定義
自定義車標(biāo)
//獲取options
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//車標(biāo)
options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.car));
//背景圖 指示東南西北
options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.lane00));
//起始點(diǎn)圖標(biāo)
options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_start));
//途經(jīng)點(diǎn)圖標(biāo)
options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
//結(jié)束點(diǎn)圖標(biāo)
options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_end));
mAMapNaviView.setViewOptions(options);
自定義路線UI及紋理
關(guān)閉自動(dòng)繪制路線
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//關(guān)閉自動(dòng)繪制路線(如果你想自行繪制路線的話湃番,必須關(guān)閉X仓!7痛椤)
options.setAutoDrawRoute(false);
options.setTrafficLine(false);
options.setAutoLockCar(true);
mAMapNaviView.setViewOptions(options);
計(jì)算路線成功后繪制路線并開啟導(dǎo)航
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
drawCustomRoute();
mAMapNavi.startNavi(NaviType.GPS);
}
private void drawCustomRoute() {
// 主路線自定義紋理
Bitmap unknownTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_no);//未知狀態(tài)
Bitmap smoothTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_green);//暢通
Bitmap slowTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow);//緩慢
Bitmap jamTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_bad);//擁堵
Bitmap veryJamTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_grayred);//超級(jí)擁堵
// 繪制自定義主路線
RouteOverLay mainRouteOverlay = new RouteOverLay(mAMapNaviView.getMap(), mAMapNavi.getNaviPath(), this);
RouteOverlayOptions options = new RouteOverlayOptions();
options.setUnknownTraffic(unknownTraffic);
options.setSmoothTraffic(smoothTraffic);
options.setSlowTraffic(slowTraffic);
options.setJamTraffic(jamTraffic);
options.setVeryJamTraffic(veryJamTraffic);
options.setLineWidth(60);//線路寬度
routeOverlayOptions.setArrowOnTrafficRoute(BitmapFactory.decodeResource(getResources(),R.drawable.custtexture_aolr));//箭頭樣式
mainRouteOverlay.setRouteOverlayOptions(options);
mainRouteOverlay.addToMap();//添加到地圖
}
自定義路口轉(zhuǎn)向提示
1)在布局文件中添加控件
<com.amap.api.navi.view.NextTurnTipView
android:id="@+id/mNextTurnTipView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
2)隱藏導(dǎo)航界面除地圖外的所有控件尊惰,綁定新的控件
//設(shè)置布局完全不可見
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mNextTurnTipView = (NextTurnTipView) findViewById(R.id.mNextTurnTipView);
mAMapNaviView.setLazyNextTurnTipView(mNextTurnTipView);
正北模式/車頭向上
mAMapNaviView.setNaviMode(AMapNaviView.NORTH_UP_MODE);//正北模式
mAMapNaviView.setNaviMode(AMapNaviView.CAR_UP_MODE);//車頭向上
自定義全覽功能
如果用系統(tǒng)自帶的樣式,可通過以下方式纬向。
添加布局
<com.amap.api.navi.view.OverviewButtonView
android:id="@+id/myOverviewButtonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
設(shè)置除地圖外其余控件不可見择浊,綁定全覽控件
mOverviewButtonView = (OverviewButtonView) findViewById(R.id.myOverviewButtonView);
//設(shè)置布局完全不可見
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyOverviewButtonView(mOverviewButtonView);
也可以自定義按鈕樣式控制全覽和繼續(xù)導(dǎo)航
控制代碼如下
//全覽
// mAMapNaviView.displayOverview();//已過時(shí)
mAMapNaviView.setShowMode(2);
//繼續(xù)導(dǎo)航
// mAMapNaviView.recoverLockMode();//已過時(shí)
mAMapNaviView.setShowMode(1);
自定義指南針
布局文件中添加新控件
<com.amap.api.navi.view.DirectionView
android:id="@+id/custom_myDirectionView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="visible" />
隱藏除地圖外其他控件,關(guān)聯(lián)新控件
//設(shè)置布局完全不可見
com.amap.api.navi.AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mDirectionView = (DirectionView) findViewById(R.id.myDirectionView);
mAMapNaviView.setLazyDirectionView(mDirectionView);
自定義路況按鈕
布局文件中添加新控件
<com.amap.api.navi.view.TrafficButtonView
android:id="@+id/myTrafficButtonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
隱藏除地圖外其他控件逾条,關(guān)聯(lián)新控件
mTrafficButtonView = (TrafficButtonView) findViewById(R.id.myTrafficButtonView);
//設(shè)置布局完全不可見
com.amap.api.navi.AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyTrafficButtonView(mTrafficButtonView);
自定義放大縮小按鈕
布局文件添加新控件
<com.amap.api.navi.view.ZoomButtonView
android:id="@+id/myZoomButtonView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
隱藏除地圖外其他控件琢岩,綁定新控件
//設(shè)置布局完全不可見
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyZoomButtonView(mZoomButtonView);
自定義路口放大圖
布局中添加新控件
<com.amap.api.navi.view.ZoomInIntersectionView
android:id="@+id/myZoomInIntersectionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
隱藏除地圖外其他控件,設(shè)置模型圖范圍及關(guān)聯(lián)新控件展示實(shí)景圖
//設(shè)置布局完全不可見
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
// 設(shè)置是否顯示路口放大圖(路口模型圖)
options.setModeCrossDisplayShow(true);
// 設(shè)置是否顯示路口放大圖(實(shí)景圖)
options.setRealCrossDisplayShow(true);
/**
* 設(shè)置路口放大圖的顯示位置师脂。
* 路口放大圖分為模型圖和實(shí)景圖担孔,這里設(shè)置的是模型圖的位置.
* 實(shí)景圖可通過自定義ZoomInIntersectionView進(jìn)行設(shè)置.
*
* 第一個(gè)參數(shù):橫屏路口放大圖顯示位置。
* 第二個(gè)參數(shù): 豎屏路口放大圖顯示位置吃警。
*/
options.setCrossLocation(new Rect(0,30,260,300), new Rect(60,10,320,200));
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyZoomInIntersectionView(mZoomInIntersectionView);
也可以通過回調(diào)展示路口大圖
@Override
public void showCross(AMapNaviCross aMapNaviCross) {
super.showCross(aMapNaviCross);
//展示實(shí)景圖
mZoomInIntersectionView.setImageBitmap(aMapNaviCross.getBitmap());
mZoomInIntersectionView.setVisibility(View.VISIBLE);
}
@Override
public void hideCross() {
super.hideCross();
//隱藏實(shí)景圖
mZoomInIntersectionView.setVisibility(View.INVISIBLE);
}
@Override
public void showModeCross(AMapModelCross aMapModelCross) {
super.showModeCross(aMapModelCross);
//展示模型圖
}
@Override
public void hideModeCross() {
super.hideModeCross();
//隱藏模型圖
}
自定義導(dǎo)航光柱(進(jìn)度條)
布局文件中添加新控件
<com.amap.api.navi.view.TrafficProgressBar
android:id="@+id/myTrafficBar"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_centerVertical="true" />
設(shè)置地圖自帶的導(dǎo)航光柱不可用糕篇,獲取新控件設(shè)置不同路況顏色值
//設(shè)置自帶的導(dǎo)航光柱不可用
AMapNaviViewOptions viewOptions = mAMapNaviView.getViewOptions();
viewOptions.setTrafficBarEnabled(false);
mAMapNaviView.setViewOptions(viewOptions);
mTrafficBarView = (TrafficProgressBar) findViewById(R.id.myTrafficBar);//獲取添加的新控件
mTrafficBarView.setUnknownTrafficColor(Color.parseColor("#0091FF"));//未知路況色值
mTrafficBarView.setSmoothTrafficColor(Color.parseColor("#00BA1F"));//暢通路況色值
mTrafficBarView.setSlowTrafficColor(Color.parseColor("#FFBA00"));//緩慢路段
mTrafficBarView.setJamTrafficColor(Color.parseColor("#F31D20"));//擁堵路段
mTrafficBarView.setVeryJamTrafficColor(Color.parseColor("#A8090B"));//超級(jí)擁堵路段
導(dǎo)航過程中,通過回調(diào)信息更新進(jìn)度條
@Override
public void onNaviInfoUpdate(NaviInfo naviinfo) {
super.onNaviInfoUpdate(naviinfo);
int allLength = mAMapNavi.getNaviPath().getAllLength();
List<AMapTrafficStatus> trafficStatuses = mAMapNavi.getTrafficStatuses(0, 0);
mTrafficBarView.update(allLength, naviinfo.getPathRetainDistance(), trafficStatuses);
}
自定義車道信息
布局文件添加新控件
<com.amap.api.navi.view.DriveWayView
android:id="@+id/myDriveWayView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
隱藏除地圖外其他布局酌心,關(guān)聯(lián)新的車道信息控件
//設(shè)置布局完全不可見
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mDriveWayView = (DriveWayView) findViewById(R.id.myDriveWayView);
mAMapNaviView.setLazyDriveWayView(mDriveWayView);
也可以在回調(diào)中解析數(shù)據(jù)拌消,展示自定義樣式
@Override
public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
StringBuffer sb = new StringBuffer();
sb.append("共" + aMapLaneInfo.frontLane.length + "車道");
for (int i = 0; i < aMapLaneInfo.frontLane.length; i++) {
//當(dāng)前車道可以選擇的動(dòng)作
int background = aMapLaneInfo.backgroundLane[i];
//當(dāng)前用戶要執(zhí)行的動(dòng)作
int recommend = aMapLaneInfo.frontLane[i];
//根據(jù)文檔中每個(gè)動(dòng)作對(duì)應(yīng)的枚舉類型,顯示對(duì)應(yīng)的圖片
try {
sb.append("安券,第" + (i + 1) + "車道為" + array[background]);
if (recommend != 255) {
sb.append("墩崩,當(dāng)前車道可 " + actions[recommend]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 車道信息說明:
* <p>
* 0xFF, 無對(duì)應(yīng)車道
* 0, 直行
* 1, 左轉(zhuǎn)
* 2, 直行+左轉(zhuǎn)
* 3, 右轉(zhuǎn)
* 4, 直行+右轉(zhuǎn)
* 5, 左掉頭
* 6, 左轉(zhuǎn)+右轉(zhuǎn)
* 7, 直行+左轉(zhuǎn)+右轉(zhuǎn)
* 8, 右掉頭
* 9, 直行+左掉頭
* 10, 直行+右掉頭
* 11, 左轉(zhuǎn)+左掉頭
* 12, 右轉(zhuǎn)+右掉頭
* 13, 直行+擴(kuò)展
* 14, 左轉(zhuǎn)+左掉頭+擴(kuò)展
* 15, 保留
* 16, 直行+左轉(zhuǎn)+左掉頭
* 17, 右轉(zhuǎn)+左掉頭
* 18, 左轉(zhuǎn)+右轉(zhuǎn)+左掉頭
* 19, 直行+右轉(zhuǎn)+左掉頭
* 20, 左轉(zhuǎn)+右掉頭
* 21, 公交車道
* 22, 空車道
* 23 可變車道
*/
String[] array = {
"直行車道"
, "左轉(zhuǎn)車道"
, "左轉(zhuǎn)或直行車道"
, "右轉(zhuǎn)車道"
, "右轉(zhuǎn)或直行車道"
, "左掉頭車道"
, "左轉(zhuǎn)或者右轉(zhuǎn)車道"
, " 左轉(zhuǎn)或右轉(zhuǎn)或直行車道"
, "右轉(zhuǎn)掉頭車道"
, "直行或左轉(zhuǎn)掉頭車道"
, "直行或右轉(zhuǎn)掉頭車道"
, "左轉(zhuǎn)或左掉頭車道"
, "右轉(zhuǎn)或右掉頭車道"
, "直行并且車道擴(kuò)展"
, "左轉(zhuǎn)+左掉頭+擴(kuò)展"
, "不可以選擇該車道"
, "直行+左轉(zhuǎn)+左掉頭車道"
, "右轉(zhuǎn)+左掉頭"
, "左轉(zhuǎn)+右轉(zhuǎn)+左掉頭"
, "直行+右轉(zhuǎn)+左掉頭"
, "左轉(zhuǎn)+右掉頭"
, "公交車道"
, "空車道"
, "可變車道"
};
String[] actions = {
"直行"
, "左轉(zhuǎn)"
, "左轉(zhuǎn)或直行"
, "右轉(zhuǎn)"
, "右轉(zhuǎn)或這行"
, "左掉頭"
, "左轉(zhuǎn)或者右轉(zhuǎn)"
, " 左轉(zhuǎn)或右轉(zhuǎn)或直行"
, "右轉(zhuǎn)掉頭"
, "直行或左轉(zhuǎn)掉頭"
, "直行或右轉(zhuǎn)掉頭"
, "左轉(zhuǎn)或左掉頭"
, "右轉(zhuǎn)或右掉頭"
, "直行并且車道擴(kuò)展"
, "左轉(zhuǎn)+左掉頭+擴(kuò)展"
, "不可以選擇"
, "直行+左轉(zhuǎn)+左掉頭"
, "右轉(zhuǎn)+左掉頭"
, "左轉(zhuǎn)+右轉(zhuǎn)+左掉頭"
, "直行+右轉(zhuǎn)+左掉頭"
, "左轉(zhuǎn)+右掉頭"
, "公交車道"
, "空車道"
, "可變車道"
};
```其他
```java
/** ------- 導(dǎo)航基本信息的回調(diào) ----- */
@Override
public void onNaviInfoUpdate(NaviInfo naviInfo) {
super.onNaviInfoUpdate(naviInfo);
/**
* 更新路口轉(zhuǎn)向圖標(biāo)
*/
if(naviInfo.getIconBitmap() != null){
nextTurnTipView.setImageBitmap(naviInfo.getIconBitmap());
}else{
nextTurnTipView.setIconType(naviInfo.getIconType());
}
/**
* 更新下一路口 路名及 距離
*/
textNextRoadName.setText(naviInfo.getNextRoadName());//路名
textNextRoadDistance.setText(NaviUtil.formatKM(naviInfo.getCurStepRetainDistance()));//距離
}
其他回調(diào)接口介紹
@Override
public void onInitNaviFailure() {
//初始化失敗
}
@Override
public void onInitNaviSuccess() {
// 初始化成功
}
@Override
public void onStartNavi(int type) {
//開始導(dǎo)航回調(diào)
}
@Override
public void onTrafficStatusUpdate() {
//交通狀態(tài)回調(diào)
}
@Override
public void onLocationChange(AMapNaviLocation location) {
//當(dāng)前位置回調(diào)
}
@Override
public void onGetNavigationText(int type, String text) {
//播報(bào)類型和播報(bào)文字回調(diào)
}
@Override
public void onGetNavigationText(String s) {
}
@Override
public void onEndEmulatorNavi() {
//結(jié)束模擬導(dǎo)航
}
@Override
public void onArriveDestination() {
//到達(dá)目的地
}
@Override
public void onCalculateRouteFailure(int errorInfo) {
//規(guī)劃路線失敗
}
@Override
public void onReCalculateRouteForYaw() {
//偏航后重新計(jì)算路線回調(diào)
}
@Override
public void onReCalculateRouteForTrafficJam() {
//擁堵后重新計(jì)算路線回調(diào)
}
@Override
public void onArrivedWayPoint(int wayID) {
//到達(dá)途徑點(diǎn)
}
@Override
public void onGpsOpenStatus(boolean enabled) {
//GPS開關(guān)狀態(tài)回調(diào)
}
@Override
public void onNaviSetting() {
//底部導(dǎo)航設(shè)置點(diǎn)擊回調(diào)
}
@Override
public void onNaviMapMode(int isLock) {
//地圖的模式,鎖屏或鎖車
}
@Override
public void onNaviCancel() {
//取消導(dǎo)航回調(diào)
finish();
}
@Override
public void onNaviTurnClick() {
//轉(zhuǎn)彎view的點(diǎn)擊回調(diào)
}
@Override
public void onNextRoadClick() {
//下一個(gè)道路View點(diǎn)擊回調(diào)
}
@Override
public void onScanViewButtonClick() {
//全覽按鈕點(diǎn)擊回調(diào)
}
@Override
public void onNaviInfoUpdated(AMapNaviInfo naviInfo) {
//已過時(shí)
}
@Override
public void updateCameraInfo(AMapNaviCameraInfo[] aMapCameraInfos) {
//更新焦點(diǎn)回調(diào)
}
@Override
public void onServiceAreaUpdate(AMapServiceAreaInfo[] amapServiceAreaInfos) {
//服務(wù)區(qū)信息回調(diào)
AMapServiceAreaInfo.getRemainDist()侯勉;//到服務(wù)區(qū)的剩余距離
}
@Override
public void onNaviInfoUpdate(NaviInfo naviinfo) {
//導(dǎo)航過程中的信息更新鹦筹,請(qǐng)看NaviInfo的具體說明
}
@Override
public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
//已過時(shí)
}
@Override
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
//已過時(shí)
}
@Override
public void showCross(AMapNaviCross aMapNaviCross) {
//顯示轉(zhuǎn)彎回調(diào)
}
@Override
public void hideCross() {
//隱藏轉(zhuǎn)彎回調(diào)
}
@Override
public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) {
//顯示車道信息
}
@Override
public void hideLaneInfo() {
//隱藏車道信息
}
@Override
public void onCalculateRouteSuccess(int[] ints) {
//多路徑算路成功回調(diào)
}
@Override
public void notifyParallelRoad(AMapNaviParallelRoadStatus aMapNaviParallelRoadStatus) {
if (aMapNaviParallelRoadStatus.getmElevatedRoadStatusFlag() == 1) {
Toast.makeText(this, "當(dāng)前在高架上", Toast.LENGTH_SHORT).show();
Log.d("wlx", "當(dāng)前在高架上");
} else if (aMapNaviParallelRoadStatus.getmElevatedRoadStatusFlag() == 2) {
Toast.makeText(this, "當(dāng)前在高架下", Toast.LENGTH_SHORT).show();
Log.d("wlx", "當(dāng)前在高架下");
}
if (aMapNaviParallelRoadStatus.getmParallelRoadStatusFlag() == 1) {
Toast.makeText(this, "當(dāng)前在主路", Toast.LENGTH_SHORT).show();
Log.d("wlx", "當(dāng)前在主路");
} else if (aMapNaviParallelRoadStatus.getmParallelRoadStatusFlag() == 2) {
Toast.makeText(this, "當(dāng)前在輔路", Toast.LENGTH_SHORT).show();
Log.d("wlx", "當(dāng)前在輔路");
}
}
@Override
public void notifyParallelRoad(int i) {
}
@Override
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
//更新交通設(shè)施信息
}
@Override
public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
//更新巡航模式的統(tǒng)計(jì)信息
}
@Override
public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
//更新巡航模式的擁堵信息
}
@Override
public void onPlayRing(int i) {
}
@Override
public void onLockMap(boolean isLock) {
//鎖地圖狀態(tài)發(fā)生變化時(shí)回調(diào)
}
@Override
public void onNaviViewLoaded() {
//導(dǎo)航頁面加載成功
}
@Override
public void onMapTypeChanged(int i) {
//地圖類型變化回調(diào)
}
@Override
public void onNaviViewShowMode(int i) {
//地圖展示形式變化回調(diào)
}
@Override
public boolean onNaviBackClick() {
return false;
}
@Override
public void showModeCross(AMapModelCross aMapModelCross) {
//展示模型路口場(chǎng)景回調(diào)
}
@Override
public void hideModeCross() {
}
@Override
public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
}
@Override
public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
//車道信息回調(diào)
}
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
AMapNaviPath naviPath = mAMapNavi.getNaviPath();
if (naviPath != null) {
if (routeOverLay == null) {
/**
* 初始化路線參數(shù)
*/
routeOverLay = new RouteOverLay(mAMapNaviView.getMap(), naviPath, this);
BitmapDescriptor smoothTraffic = BitmapDescriptorFactory.fromResource(R.drawable.custtexture_green);
BitmapDescriptor unknownTraffic = BitmapDescriptorFactory.fromResource(R.drawable.custtexture_no);
BitmapDescriptor slowTraffic = BitmapDescriptorFactory.fromResource(R.drawable.custtexture_slow);
BitmapDescriptor jamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.custtexture_bad);
BitmapDescriptor veryJamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.custtexture_grayred);
RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
routeOverlayOptions.setSmoothTraffic(smoothTraffic.getBitmap());
routeOverlayOptions.setUnknownTraffic(unknownTraffic.getBitmap());
routeOverlayOptions.setSlowTraffic(slowTraffic.getBitmap());
routeOverlayOptions.setJamTraffic(jamTraffic.getBitmap());
routeOverlayOptions.setVeryJamTraffic(veryJamTraffic.getBitmap());
routeOverLay.setRouteOverlayOptions(routeOverlayOptions);
}
if (routeOverLay != null) {
routeOverLay.setAMapNaviPath(naviPath);
routeOverLay.addToMap();
}
float bearing = NaviUtil.getRotate(mStartLatlng, naviPath.getCoordList().get(1));
if (mStartLatlng != null) {
carOverlay.reset();
/**
* 繪制自車位置
*/
carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), bearing);
if (naviPath.getEndPoint() != null) {
LatLng latlng = new LatLng(naviPath.getEndPoint().getLatitude(), naviPath.getEndPoint().getLongitude());
carOverlay.setEndPoi(latlng);
}
}
}
/**
* 開啟模擬導(dǎo)航
*/
mAMapNavi.startNavi(NaviType.EMULATOR);
}
/**
* 繪制轉(zhuǎn)彎箭頭
*/
private int roadIndex;
public void drawArrow(NaviInfo naviInfo) {
try {
if (roadIndex != naviInfo.getCurStep()) {
List<NaviLatLng> arrow = routeOverLay.getArrowPoints(naviInfo.getCurStep());
if (routeOverLay != null && arrow != null && arrow.size() > 0) {
routeOverLay.drawArrow(arrow);
roadIndex = naviInfo.getCurStep();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
@Override
public void onCalculateRouteFailure(AMapCalcRouteResult result) {
//路線計(jì)算失敗
Log.e("dm", "--------------------------------------------");
Log.i("dm", "路線計(jì)算失敗:錯(cuò)誤碼=" + result.getErrorCode() + ",Error Message= " + result.getErrorDescription());
Log.i("dm", "錯(cuò)誤碼詳細(xì)鏈接見:http://lbs.amap.com/api/android-navi-sdk/guide/tools/errorcode/");
Log.e("dm", "--------------------------------------------");
Toast.makeText(this, "errorInfo:" + result.getErrorDetail() + ", Message:" + result.getErrorDescription(), Toast.LENGTH_LONG).show();
}
@Override
public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {
}
@Override
public void onGpsSignalWeak(boolean b) {
//GPS信號(hào)弱
}