(内容:设置导航路线规划策略、搜索框添加一键清除按钮、避免多次进入导航实例)
(内容:卫星图、定位模式:普通跟随罗盘、指南针位置、SD卡导入离线地图、在线更新离线地图)
------------------------------------------------------------------------------------------------------------------------------------------
前面实现了轨迹绘制功能,后面添加了轨迹回放功能。
可还原轨迹速度,显示轨迹时间进度,暂停播放轨迹,加速播放。
效果:
------ 红虚线:起始点和终点连接直线
------ 绿虚线:轨迹趋势线
—— 蓝实线:实时绘制的轨迹
支持x1,x5,x10倍速播放轨迹。
暂停,继续,重复播放。
------------------------------------------------------------------------------------------------------------------------------------------
代码实现:
主要状态:
/** 播放倍数 */
private TextView textPlaySpeed;
/** 播放状态控制图标 */
private ImageView imagePlayState;
/** 播放状态:暂停、播放 */
private boolean isRoutePlaying = true;
/** 播放时间 */
private TextView textPlayTime;
/** 是否播放完毕 */
private boolean isRouteFinished = false;
public double mRouteLatitude = 0.0;
public double mRouteLongitude = 0.0;
/** 轨迹文件夹路径 */
private final String ROUTE_PATH = Constant.RouteTrack.PATH;
/** 当前轨迹的路径 */
private String filePath = “”;
绘制轨迹线程:
nowIndex = 1;
for (int i = 0; i < points.size(); i++) {
if (isActivityShowing) {
if (isRoutePlaying) {
Message messageFollow = new Message();
messageFollow.what = 1;
drawRouteHandler.sendMessage(messageFollow);
try {
Thread.sleep(1000 / MyApplication.routePlaySpeed);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
// 暂停
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (!isRoutePlaying);
}
} else {
MyLog.v(“[Loop]Return in case activity is onDestory.”);
return;
}
}
绘制轨迹趋势底图,起点终点虚线:
// 绘制轨迹底图
PolylineOptions polylineOptionBg = new PolylineOptions();
polylineOptionBg.width(10); // 折线线宽, 默认为 5, 单位:像素
polylineOptionBg.dottedLine(true); // 折线是否虚线
polylineOptionBg.color(0xAA009966); // 折线颜色
polylineOptionBg.points(points); // 折线坐标点列表:[2,10000],且不能包含null
polylineOptionBg.keepScale(true); // 纹理宽、高是否保持原比例渲染
OverlayOptions ooPolyline = polylineOptionBg;
mBaiduMap.addOverlay(ooPolyline);
// 绘制起点终点直线
PolylineOptions polylineOptionDirec = new PolylineOptions();
polylineOptionDirec.width(10); // 折线线宽, 默认为 5, 单位:像素
polylineOptionDirec.dottedLine(true); // 折线是否虚线