高德导航sdk版本7.6.0
1.起终点算路,手动开启导航:
//poiList为途经点,起始点和途经点可以为null,起始点为null时已当前位置为起始点导航
//第四个参数为通行方式(步行、驾车等)
AmapNaviParams params =new AmapNaviParams(new Poi("起始点", startLatlng, ""), poiList, new Poi("结束点", endLatlng, ""), AmapNaviType.DRIVER);
//开启语音提示
params.setUseInnerVoice(true);
//第三个参数为回调接口
AmapNaviPage.getInstance().showRouteActivity(getApplicationContext(), params, callback);
2.起终点算路,自动开启导航:
//与上面的方式大同小异,调用AmapNaviParams的重载方法,最后的参数为AmapPageType.Navi。
AmapNaviParams amapNaviParams = new AmapNaviParams(start, poiList, end, AmapNaviType.DRIVER, AmapPageType.NAVI);
3.不同通行方式的导航
首先在布局内添加导航的地图
<?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>
设置路径规划策略,开始计算导航路径
//初始化完成
@Override
public void onInitNaviSuccess() {
super.onInitNaviSuccess();
/**
* 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数:
*
* @congestion 躲避拥堵
* @avoidhightspeed 不走高速
* @cost 避免收费
* @hightspeed 高速优先
* @multipleroute 多路径
*
* 说明: 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。
* 注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true
*/
int strategy = 0;
try {
//再次强调,最后一个参数为true时代表多路径,否则代表单路径
strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
} catch (Exception e) {
e.printStackTrace();
}
//驾车路径规划
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
//步行路径规划
mAMapNavi.calculateWalkRoute(new NaviLatLng(39.925846, 116.435765), new NaviLatLng(39.925846, 116.532765));
//骑行路径规划
mAMapNavi.calculateRideRoute(new NaviLatLng(39.925846, 116.435765), new NaviLatLng(39.925846, 116.532765));
}
//计算线路完成开始导航
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
super.onCalculateRouteSuccess(aMapCalcRouteResult);
mAMapNavi.startNavi(NaviType.GPS);
}
4.导航UI自定义
自定义车标
//获取options
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//车标
options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.car));
//背景图 指示东南西北
options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.lane00));
//起始点图标
options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_start));
//途经点图标
options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
//结束点图标
options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_end));
mAMapNaviView.setViewOptions(options);
自定义路线UI及纹理
关闭自动绘制路线
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//关闭自动绘制路线(如果你想自行绘制路线的话,必须关闭!!!)
options.setAutoDrawRoute(false);
options.setTrafficLine(false);
options.setAutoLockCar(true);
mAMapNaviView.setViewOptions(options);
计算路线成功后绘制路线并开启导航
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
drawCustomRoute();
mAMapNavi.startNavi(NaviType.GPS);
}
private void drawCustomRoute() {
// 主路线自定义纹理
Bitmap unknownTraffic = BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_no);//未知状态
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);//超级拥堵
// 绘制自定义主路线
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();//添加到地图
}
自定义路口转向提示
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)隐藏导航界面除地图外的所有控件,绑定新的控件
//设置布局完全不可见
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);//车头向上
自定义全览功能
如果用系统自带的样式,可通过以下方式。
添加布局
<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"/>
设置除地图外其余控件不可见,绑定全览控件
mOverviewButtonView = (OverviewButtonView) findViewById(R.id.myOverviewButtonView);
//设置布局完全不可见
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyOverviewButtonView(mOverviewButtonView);
也可以自定义按钮样式控制全览和继续导航
控制代码如下
//全览
// mAMapNaviView.displayOverview();//已过时
mAMapNaviView.setShowMode(2);
//继续导航
// mAMapNaviView.recoverLockMode();//已过时
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" />
隐藏除地图外其他控件,关联新控件
//设置布局完全不可见
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"
/>
隐藏除地图外其他控件,关联新控件
mTrafficButtonView = (TrafficButtonView) findViewById(R.id.myTrafficButtonView);
//设置布局完全不可见
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"
/>
隐藏除地图外其他控件,绑定新控件
//设置布局完全不可见
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"
/>
隐藏除地图外其他控件,设置模型图范围及关联新控件展示实景图
//设置布局完全不可见
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
// 设置是否显示路口放大图(路口模型图)
options.setModeCrossDisplayShow(true);
// 设置是否显示路口放大图(实景图)
options.setRealCrossDisplayShow(true);
/**
* 设置路口放大图的显示位置。
* 路口放大图分为模型图和实景图,这里设置的是模型图的位置.
* 实景图可通过自定义ZoomInIntersectionView进行设置.
*
* 第一个参数:横屏路口放大图显示位置。
* 第二个参数: 竖屏路口放大图显示位置。
*/
options.setCrossLocation(new Rect(0,30,260,300), new Rect(60,10,320,200));
mAMapNaviView.setViewOptions(options);
mAMapNaviView.setLazyZoomInIntersectionView(mZoomInIntersectionView);
也可以通过回调展示路口大图
@Override
public void showCross(AMapNaviCross aMapNaviCross) {
super.showCross(aMapNaviCross);
//展示实景图
mZoomInIntersectionView.setImageBitmap(aMapNaviCross.getBitmap());
mZoomInIntersectionView.setVisibility(View.VISIBLE);
}
@Override
public void hideCross() {
super.hideCross();
//隐藏实景图
mZoomInIntersectionView.setVisibility(View.INVISIBLE);
}
@Override
public void showModeCross(AMapModelCross aMapModelCross) {
super.showModeCross(aMapModelCross);
//展示模型图
}
@Override
public void hideModeCross() {
super.hideModeCross();
//隐藏模型图
}
自定义导航光柱(进度条)
布局文件中添加新控件
<com.amap.api.navi.view.TrafficProgressBar
android:id="@+id/myTrafficBar"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_centerVertical="true" />
设置地图自带的导航光柱不可用,获取新控件设置不同路况颜色值
//设置自带的导航光柱不可用
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"));//超级拥堵路段
导航过程中,通过回调信息更新进度条
@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"/>
隐藏除地图外其他布局,关联新的车道信息控件
//设置布局完全不可见
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
options.setLayoutVisible(false);
mAMapNaviView.setViewOptions(options);
mDriveWayView = (DriveWayView) findViewById(R.id.myDriveWayView);
mAMapNaviView.setLazyDriveWayView(mDriveWayView);
也可以在回调中解析数据,展示自定义样式
@Override
public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
StringBuffer sb = new StringBuffer();
sb.append("共" + aMapLaneInfo.frontLane.length + "车道");
for (int i = 0; i < aMapLaneInfo.frontLane.length; i++) {
//当前车道可以选择的动作
int background = aMapLaneInfo.backgroundLane[i];
//当前用户要执行的动作
int recommend = aMapLaneInfo.frontLane[i];
//根据文档中每个动作对应的枚举类型,显示对应的图片
try {
sb.append(",第" + (i + 1) + "车道为" + array[background]);
if (recommend != 255) {
sb.append(",当前车道可 " + actions[recommend]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 车道信息说明:
* <p>
* 0xFF, 无对应车道
* 0, 直行
* 1, 左转
* 2, 直行+左转
* 3, 右转
* 4, 直行+右转
* 5, 左掉头
* 6, 左转+右转
* 7, 直行+左转+右转
* 8, 右掉头
* 9, 直行+左掉头
* 10, 直行+右掉头
* 11, 左转+左掉头
* 12, 右转+右掉头
* 13, 直行+扩展
* 14, 左转+左掉头+扩展
* 15, 保留
* 16, 直行+左转+左掉头
* 17, 右转+左掉头
* 18, 左转+右转+左掉头
* 19, 直行+右转+左掉头
* 20, 左转+右掉头
* 21, 公交车道
* 22, 空车道
* 23 可变车道
*/
String[] array = {
"直行车道"
, "左转车道"
, "左转或直行车道"
, "右转车道"
, "右转或直行车道"
, "左掉头车道"
, "左转或者右转车道"
, " 左转或右转或直行车道"
, "右转掉头车道"
, "直行或左转掉头车道"
, "直行或右转掉头车道"
, "左转或左掉头车道"
, "右转或右掉头车道"
, "直行并且车道扩展"
, "左转+左掉头+扩展"
, "不可以选择该车道"
, "直行+左转+左掉头车道"
, "右转+左掉头"
, "左转+右转+左掉头"
, "直行+右转+左掉头"
, "左转+右掉头"
, "公交车道"
, "空车道"
, "可变车道"
};
String[] actions = {
"直行"
, "左转"
, "左转或直行"
, "右转"
, "右转或这行"
, "左掉头"
, "左转或者右转"
, " 左转或右转或直行"
, "右转掉头"
, "直行或左转掉头"
, "直行或右转掉头"
, "左转或左掉头"
, "右转或右掉头"
, "直行并且车道扩展"
, "左转+左掉头+扩展"
, "不可以选择"
, "直行+左转+左掉头"
, "右转+左掉头"
, "左转+右转+左掉头"
, "直行+右转+左掉头"
, "左转+右掉头"
, "公交车道"
, "空车道"
, "可变车道"
};
```其他
```java
/** ------- 导航基本信息的回调 ----- */
@Override
public void onNaviInfoUpdate(NaviInfo naviInfo) {
super.onNaviInfoUpdate(naviInfo);
/**
* 更新路口转向图标
*/
if(naviInfo.getIconBitmap() != null){
nextTurnTipView.setImageBitmap(naviInfo.getIconBitmap());
}else{
nextTurnTipView.setIconType(naviInfo.getIconType());
}
/**
* 更新下一路口 路名及 距离
*/
textNextRoadName.setText(naviInfo.getNextRoadName());//路名
textNextRoadDistance.setText(NaviUtil.formatKM(naviInfo.getCurStepRetainDistance()));//距离
}
其他回调接口介绍
@Override
public void onInitNaviFailure() {
//初始化失败
}
@Override
public void onInitNaviSuccess() {
// 初始化成功
}
@Override
public void onStartNavi(int type) {
//开始导航回调
}
@Override
public void onTrafficStatusUpdate() {
//交通状态回调
}
@Override
public void onLocationChange(AMapNaviLocation location) {
//当前位置回调
}
@Override
public void onGetNavigationText(int type, String text) {
//播报类型和播报文字回调
}
@Override
public void onGetNavigationText(String s) {
}
@Override
public void onEndEmulatorNavi() {
//结束模拟导航
}
@Override
public void onArriveDestination() {
//到达目的地
}
@Override
public void onCalculateRouteFailure(int errorInfo) {
//规划路线失败
}
@Override
public void onReCalculateRouteForYaw() {
//偏航后重新计算路线回调
}
@Override
public void onReCalculateRouteForTrafficJam() {
//拥堵后重新计算路线回调
}
@Override
public void onArrivedWayPoint(int wayID) {
//到达途径点
}
@Override
public void onGpsOpenStatus(boolean enabled) {
//GPS开关状态回调
}
@Override
public void onNaviSetting() {
//底部导航设置点击回调
}
@Override
public void onNaviMapMode(int isLock) {
//地图的模式,锁屏或锁车
}
@Override
public void onNaviCancel() {
//取消导航回调
finish();
}
@Override
public void onNaviTurnClick() {
//转弯view的点击回调
}
@Override
public void onNextRoadClick() {
//下一个道路View点击回调
}
@Override
public void onScanViewButtonClick() {
//全览按钮点击回调
}
@Override
public void onNaviInfoUpdated(AMapNaviInfo naviInfo) {
//已过时
}
@Override
public void updateCameraInfo(AMapNaviCameraInfo[] aMapCameraInfos) {
//更新焦点回调
}
@Override
public void onServiceAreaUpdate(AMapServiceAreaInfo[] amapServiceAreaInfos) {
//服务区信息回调
AMapServiceAreaInfo.getRemainDist();//到服务区的剩余距离
}
@Override
public void onNaviInfoUpdate(NaviInfo naviinfo) {
//导航过程中的信息更新,请看NaviInfo的具体说明
}
@Override
public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
//已过时
}
@Override
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
//已过时
}
@Override
public void showCross(AMapNaviCross aMapNaviCross) {
//显示转弯回调
}
@Override
public void hideCross() {
//隐藏转弯回调
}
@Override
public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) {
//显示车道信息
}
@Override
public void hideLaneInfo() {
//隐藏车道信息
}
@Override
public void onCalculateRouteSuccess(int[] ints) {
//多路径算路成功回调
}
@Override
public void notifyParallelRoad(AMapNaviParallelRoadStatus aMapNaviParallelRoadStatus) {
if (aMapNaviParallelRoadStatus.getmElevatedRoadStatusFlag() == 1) {
Toast.makeText(this, "当前在高架上", Toast.LENGTH_SHORT).show();
Log.d("wlx", "当前在高架上");
} else if (aMapNaviParallelRoadStatus.getmElevatedRoadStatusFlag() == 2) {
Toast.makeText(this, "当前在高架下", Toast.LENGTH_SHORT).show();
Log.d("wlx", "当前在高架下");
}
if (aMapNaviParallelRoadStatus.getmParallelRoadStatusFlag() == 1) {
Toast.makeText(this, "当前在主路", Toast.LENGTH_SHORT).show();
Log.d("wlx", "当前在主路");
} else if (aMapNaviParallelRoadStatus.getmParallelRoadStatusFlag() == 2) {
Toast.makeText(this, "当前在辅路", Toast.LENGTH_SHORT).show();
Log.d("wlx", "当前在辅路");
}
}
@Override
public void notifyParallelRoad(int i) {
}
@Override
public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
//更新交通设施信息
}
@Override
public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
//更新巡航模式的统计信息
}
@Override
public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
//更新巡航模式的拥堵信息
}
@Override
public void onPlayRing(int i) {
}
@Override
public void onLockMap(boolean isLock) {
//锁地图状态发生变化时回调
}
@Override
public void onNaviViewLoaded() {
//导航页面加载成功
}
@Override
public void onMapTypeChanged(int i) {
//地图类型变化回调
}
@Override
public void onNaviViewShowMode(int i) {
//地图展示形式变化回调
}
@Override
public boolean onNaviBackClick() {
return false;
}
@Override
public void showModeCross(AMapModelCross aMapModelCross) {
//展示模型路口场景回调
}
@Override
public void hideModeCross() {
}
@Override
public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
}
@Override
public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
//车道信息回调
}
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
AMapNaviPath naviPath = mAMapNavi.getNaviPath();
if (naviPath != null) {
if (routeOverLay == null) {
/**
* 初始化路线参数
*/
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);
}
}
}
/**
* 开启模拟导航
*/
mAMapNavi.startNavi(NaviType.EMULATOR);
}
/**
* 绘制转弯箭头
*/
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) {
//路线计算失败
Log.e("dm", "--------------------------------------------");
Log.i("dm", "路线计算失败:错误码=" + result.getErrorCode() + ",Error Message= " + result.getErrorDescription());
Log.i("dm", "错误码详细链接见: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信号弱
}