[2.13.0] taxi/bus 算法更新

This commit is contained in:
wangmingjun
2022-11-25 17:34:28 +08:00
parent 8f370c7c4a
commit 36cecbaaba
5 changed files with 193 additions and 184 deletions

View File

@@ -70,7 +70,7 @@ import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STAT
public class BusPassengerModel {
private static final String TAG = BusPassengerModel.class.getSimpleName();
private List<LatLng> mRoutePoints = new ArrayList<>();
private List<Location> mRoutePoints = new ArrayList<>();
private static final class SingletonHolder {
private static final BusPassengerModel INSTANCE = new BusPassengerModel();
@@ -88,13 +88,15 @@ public class BusPassengerModel {
private IBusPassegerDriverStatusCallback mDriverStatusCallback; //出车收车状态
private IBusPassengerRouteLineInfoCallback mRouteLineInfoCallback; // bus路线信息更新
private double mLongitude, mLatitude;
// private double mLongitude, mLatitude;
private Location mLocation = null;
private BusPassengerRoutesResult routesResult = null;
List<BusPassengerStation> mStations = new ArrayList<>();
private int mNextStationIndex = 0;// 要到达站的index
private List<LatLng> mTwoStationsRouts = new ArrayList<>();
private List<Location> mTwoStationsRouts = new ArrayList<>();
private int mPreRouteIndex = 0;
private static final int MSG_QUERY_BUS_P_STATION = 1001;
private final Handler handler = new Handler(new Handler.Callback() {
@@ -307,8 +309,9 @@ public class BusPassengerModel {
public void onCarLocationChanged2( Location location ) {
//位置变化时通过围栏判断是否到达x点
// TODO: 2022/3/31
mLongitude = location.getLongitude();
mLatitude = location.getLatitude();
// mLongitude = location.getLongitude();
// mLatitude = location.getLatitude();
mLocation = location;
for (IBusPassengerControllerStatusCallback callback :mControllerStatusCallbackMap.values()){
callback.onCarLocationChanged(location);
}
@@ -403,8 +406,8 @@ public class BusPassengerModel {
public void updateRoutePoints(List<MessagePad.Location> routePoints){
mRoutePoints.clear();
List<LatLng> latLngModels = CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjListCommon(mContext,routePoints);
List<Location> latLngModels = CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjLocations(mContext,routePoints);
mRoutePoints.addAll(latLngModels);
calculateTwoStationsRoute();
}
@@ -419,10 +422,12 @@ public class BusPassengerModel {
BusPassengerStation stationNext = mStations.get(mNextStationIndex);
BusPassengerStation stationCur = mStations.get(mNextStationIndex - 1);
//当前站在轨迹中对应的点
int currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndex(mRoutePoints
int currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(0
,mRoutePoints
,stationCur.getGcjLon(),stationCur.getGcjLat());
//要前往的站在轨迹中对应的点
int nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndex(mRoutePoints
int nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(currentRouteIndex
,mRoutePoints
,stationNext.getGcjLon(),stationNext.getGcjLat());
if (currentRouteIndex < nextRouteIndex){ //如果找到的next在起点的轨迹前面直接舍弃这个轨迹不显示
mTwoStationsRouts.addAll(mRoutePoints.subList(currentRouteIndex,nextRouteIndex));
@@ -448,22 +453,28 @@ public class BusPassengerModel {
if (mTwoStationsRouts.size() == 0){
calculateTwoStationsRoute();
}
if (mTwoStationsRouts.size() > 0){
List<LatLng> lastPoints = CoordinateCalculateRouteUtil
.getRemainPointListByCompare(mTwoStationsRouts,mLongitude,mLatitude);
float lastSumLength = 0;
if (lastPoints.size() == 1){ //只是最后一个点,计算当前位置和最后一个点的距离
lastSumLength = CoordinateUtils.calculateLineDistance(
lastPoints.get(0).longitude, lastPoints.get(0).latitude,
mLongitude, mLatitude);
}else {
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
if (mTwoStationsRouts.size() > 0 && mLocation != null){
Map<Integer,List<Location>> lastPointsMap = CoordinateCalculateRouteUtil
.getRemainPointListByCompareNew(mPreRouteIndex,mTwoStationsRouts,mLocation);
for (int index: lastPointsMap.keySet()) {
mPreRouteIndex = index;
break;
}
double lastTime = lastSumLength / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 ; //秒
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "lastSumLength = " + lastSumLength);
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.routePlanningToNextStationChanged((long)lastSumLength,(long) lastTime);
for (List<Location> lastPoints: lastPointsMap.values()){
float lastSumLength = 0;
if (lastPoints.size() == 1){ //只是最后一个点,计算当前位置和最后一个点的距离
lastSumLength = CoordinateUtils.calculateLineDistance(
lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(),
mLocation.getLongitude(), mLocation.getLatitude());
}else {
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
}
double lastTime = lastSumLength / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 ; //秒
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "lastSumLength = " + lastSumLength);
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.routePlanningToNextStationChanged((long)lastSumLength,(long) lastTime);
}
}
}
}
@@ -490,13 +501,18 @@ public class BusPassengerModel {
}
public void loopRouteAndWipe() {
if (mRoutePoints != null && mRoutePoints.size() > 0){
if (mRoutePoints != null && mRoutePoints.size() > 0 && mLocation != null){
int haveArrivedIndex = CoordinateCalculateRouteUtil
.getArrivedPointIndex(mRoutePoints,mLongitude,mLatitude);
.getArrivedPointIndexNew(mPreRouteIndex,
mRoutePoints,
mLocation.getLongitude(),
mLocation.getLatitude());
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "thread = "+ Thread.currentThread().getName()+" haveArrivedIndex== " + haveArrivedIndex);
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.routeResult(mRoutePoints,haveArrivedIndex);
List<LatLng> routePoints = CoordinateCalculateRouteUtil
.coordinateConverterLocationToLatLng(mContext,mRoutePoints);
mAutopilotPlanningCallback.routeResult(routePoints,haveArrivedIndex);
}
}
}
@@ -505,8 +521,10 @@ public class BusPassengerModel {
* 设置小地图路径的起终点marker
*/
public void setRouteLineMarker(){
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.setLineMarker(mRoutePoints);
if (mAutopilotPlanningCallback != null && mRoutePoints != null){
List<LatLng> routePoints = CoordinateCalculateRouteUtil
.coordinateConverterLocationToLatLng(mContext,mRoutePoints);
mAutopilotPlanningCallback.setLineMarker(routePoints);
}
}

View File

@@ -197,10 +197,11 @@ public class BusPassengerMapDirectionView
mCarMarker.setToTop();
}
//圈定地图显示范围
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
if (mLinePointsLatLng.size() > 0){
//圈定地图显示范围
//存放经纬度
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
for (int i = 0; i < mLinePointsLatLng.size(); i++) {
boundsBuilder.include(mLinePointsLatLng.get(i));
}
@@ -208,13 +209,15 @@ public class BusPassengerMapDirectionView
//第二个参数为四周留空宽度
mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(),100,100,100,100));
}
// else {
// //设置希望展示的地图缩放级别
} else {
boundsBuilder.include(currentLatLng);
//第二个参数为四周留空宽度
mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(),100,100,100,100));
//设置希望展示的地图缩放级别
// CameraPosition cameraPosition = new CameraPosition.Builder()
// .target(mCarMarker.getPosition()).tilt(0).bearing(location.getBearing()).zoom(zoomLevel).build();
// mAMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
// }
}
}

View File

@@ -21,20 +21,36 @@ import mogo.telematics.pad.MessagePad;
*/
public class CoordinateCalculateRouteUtil {
public static float calculateRouteSumLength(List<LatLng> points){
public static <T> float calculateRouteSumLength(List<T> points){
if (null == points || points.size() == 0) return 0;
float sumLength = 0;
//计算全路径总距离
for (int i = 0;i + 1< points.size();i++){
double preLat = points.get(i).latitude;
double preLon = points.get(i).longitude;
double laLat = points.get(i+1).latitude;
double laLon = points.get(i+1).longitude;
if (points.get(1) instanceof Location){
//计算全路径总距离
for (int i = 0;i + 1< points.size();i++){
Location locationPre = (Location) points.get(i);
Location location = (Location) points.get(i+1);
double preLat = locationPre.getLatitude();
double preLon = locationPre.getLongitude();
double laLat = location.getLatitude();
double laLon = location.getLongitude();
float length = CoordinateUtils.calculateLineDistance(laLon,laLat,preLon,preLat);
sumLength += length;
float length = CoordinateUtils.calculateLineDistance(laLon,laLat,preLon,preLat);
sumLength += length;
}
}else if (points.get(1) instanceof LatLng){
for (int i = 0;i + 1< points.size();i++){
LatLng locationPre = (LatLng) points.get(i);
LatLng location = (LatLng) points.get(i+1);
double preLat = locationPre.latitude;
double preLon = locationPre.longitude;
double laLat = location.latitude;
double laLon = location.longitude;
float length = CoordinateUtils.calculateLineDistance(laLon,laLat,preLon,preLat);
sumLength += length;
}
}
return sumLength;
}
@@ -65,75 +81,6 @@ public class CoordinateCalculateRouteUtil {
return latLng;
}
/**
* 根据实时定位的坐标确定出已行驶到那个坐标点 todo 有问题 暂不使用
* @param mRoutePoints
* @param realLon
* @param realLat
* @return 返回剩余路径集合
*/
@Deprecated
public static List<LatLng> getCurrentPoinByCompare(List<LatLng> mRoutePoints,double realLon,double realLat) {
// 疑似坐标 先以坐标中间1/2为第一个比对点
int currentIndex = Math.round(mRoutePoints.size()/2);
LatLng currentLatLng = mRoutePoints.get(currentIndex);
//差值初始化
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
,currentLatLng.longitude,currentLatLng.latitude);// lon,lat, prelon, prelat
List<LatLng> latePoints = new ArrayList<>();
//与选中点左右比较
if (currentIndex -1 >= 0 && currentIndex+1<= mRoutePoints.size()-1){
LatLng leftCurrentLatLng = mRoutePoints.get(currentIndex -1);
LatLng rightCurentLatLng = mRoutePoints.get(currentIndex + 1);
float leftDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
,leftCurrentLatLng.longitude,leftCurrentLatLng.latitude);
float rightDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat,rightCurentLatLng.longitude,rightCurentLatLng.latitude);
if (rightDiffDis < leftDiffDis){ //靠近了右半边
baseDiffDis = rightDiffDis;
for (int i = currentIndex +1; i+1 <mRoutePoints.size() ;i++){
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat
,mRoutePoints.get(i).longitude,mRoutePoints.get(i).latitude);
// Logger.d(M_TAXI + "Compare右半边集合", "点:"+i+"------------baseDiffDis = "+baseDiffDis+"---diff="+diff);
if (baseDiffDis >= diff){
baseDiffDis = diff;
currentIndex = i;
if (i == mRoutePoints.size()-1){
latePoints.addAll(mRoutePoints);
}
}else {
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
return latePoints;
}
}
}else if (rightDiffDis > leftDiffDis){ //靠近左半边
baseDiffDis = leftDiffDis;
for (int j = currentIndex-1; j -1 >=0 ;j++){
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat,mRoutePoints.get(j).longitude,mRoutePoints.get(j).latitude);
// Logger.d(M_TAXI + "Compare左半边集合", "点:"+j+"------------baseDiffDis = "+baseDiffDis+"---diff="+diff);
if (baseDiffDis >= diff){
baseDiffDis = diff;
currentIndex = j;
if (j == 0){
latePoints.addAll(mRoutePoints);
}
}else {
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
return latePoints;
}
}
}else {
// Logger.d(M_TAXI + "正好相等", "点:"+currentIndex+"------------baseDiffDis = "+baseDiffDis+"---diff="+leftDiffDis);
latePoints.addAll(mRoutePoints.subList(currentIndex,currentIndex));
return latePoints;
}
}
return latePoints;
}
/**
* 简单粗暴 直接比较 todo 需要优化
* @param mRoutePoints
@@ -239,11 +186,40 @@ public class CoordinateCalculateRouteUtil {
return list;
}
public static Map<Integer,List<LatLng>> getRemainPointListByCompareNew(int preIndex,
public static List<Location> coordinateConverterLatlngToLocation(List<LatLng> models) {
//转成MogoLatLng集合
List<Location> list = new ArrayList<>();
for (LatLng m : models) {
Location location = new Location("gcj_provider");
location.setLatitude(m.latitude);
location.setLongitude(m.longitude);
list.add(location);
}
return list;
}
public static List<LatLng> coordinateConverterLocationToLatLng(Context mContext, List<Location> models) {
//转成MogoLatLng集合
List<LatLng> list = new ArrayList<>();
for (Location m : models) {
LatLng mogoLatLng = coordinateConverterWgsToGcj(mContext, m.getLongitude(),m.getLatitude());
list.add(mogoLatLng);
}
return list;
}
/**
* 根据前一个index经纬度航向角确认剩余轨迹
* @param preIndex
* @param mRoutePoints
* @param realLocation
* @return
*/
public static Map<Integer,List<Location>> getRemainPointListByCompareNew(int preIndex,
List<Location> mRoutePoints,
Location realLocation) {
Map<Integer,List<LatLng>> routePonits = new HashMap<>();
List<LatLng> latePoints = new ArrayList<>(); // 剩余轨迹集合
Map<Integer,List<Location>> routePonits = new HashMap<>();
List<Location> latePoints = new ArrayList<>(); // 剩余轨迹集合
int currentIndex = 0; //记录疑似点
if (mRoutePoints.size() > preIndex){
//基础点
@@ -269,13 +245,13 @@ public class CoordinateCalculateRouteUtil {
Logger.d( "calculateRouteSumLength", "点:"+currentIndex+"-------是最近的点------ ");
if (currentIndex == mRoutePoints.size()-1){
Location location = mRoutePoints.get(currentIndex);
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
latePoints.add(latLng);
// LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
latePoints.add(location);
}else {
List<Location> locations = mRoutePoints.subList(currentIndex,mRoutePoints.size()-1);
for (Location location: locations) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
latePoints.add(latLng);
// LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
latePoints.add(location);
}
}
routePonits.put(currentIndex,latePoints);
@@ -284,27 +260,27 @@ public class CoordinateCalculateRouteUtil {
return routePonits;
}
public static int getArrivedPointIndexNew(List<Location> mRoutePoints,
Location realLocation) {
int currentIndex = 0; //记录疑似点 //基础点
public static int getArrivedPointIndexNew(int preIndex, List<Location> mRoutePoints,
double realLon,double realLat) {
int currentIndex = preIndex; //记录疑似点 //基础点
Location baseLatLng = mRoutePoints.get(0);
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLocation.getLongitude(),
realLocation.getLatitude()
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLon,
realLat
, baseLatLng.getLongitude(), baseLatLng.getLongitude());// lon,lat, prelon, prelat
for (int i = 0; i < mRoutePoints.size(); i++) {
Location latLng = mRoutePoints.get(i);
//todo 先看index对应点的方向和realLocation方向是否一致 方向角度不能过90度
if (Math.abs(realLocation.getBearing() - latLng.getBearing()) <= 90) {
float diff = CoordinateUtils.calculateLineDistance(realLocation.getLongitude(),
realLocation.getLatitude(),
// if (Math.abs(realLocation.getBearing() - latLng.getBearing()) <= 90) {
float diff = CoordinateUtils.calculateLineDistance(realLon,
realLat,
latLng.getLongitude(), latLng.getLatitude());
if (baseDiffDis > diff) {
if (baseDiffDis > diff && i>currentIndex) {
// Logger.d(M_TAXI + "calculateRouteSumLength", "点:"+i+"-------先记录点----- ");
baseDiffDis = diff;
currentIndex = i;
}
}
// }
}
Logger.d("calculateRouteSumLength", "点:" + currentIndex + "-------是最近的点------ ");
return currentIndex;

View File

@@ -116,12 +116,14 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
private ITaxiPassengerVeloctityCallback mVeloctityCallback;//道路限速返回
private int mPreRouteIndex = 0;
private Disposable subscribe;
private int delayTime = 2;
private double mLongitude, mLatitude;
private List<LatLng> mLocationsModels = new ArrayList<>();
private List<Location> mLocationsModels = new ArrayList<>();
private TaxiPassengerModel() {
}
@@ -425,21 +427,6 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
}
}
/**
* 计算订单起终距离
* @return
*/
public int calculateOrderDistanceSum(){
double endLon = mCurrentOCHOrder.endSiteGcjPoint.get(0);
double endLat = mCurrentOCHOrder.endSiteGcjPoint.get(1);
double startLon = mCurrentOCHOrder.startSiteGcjPoint.get(0);
double startLat = mCurrentOCHOrder.startSiteGcjPoint.get(1);
double distance = CoordinateUtils.calculateLineDistance(
endLon, endLat,
startLon, startLat);
return new Double(distance).intValue();
}
//监听网络变化,避免启动机器时无网导致无法更新订单信息
private final IMogoIntentListener mNetWorkIntentListener = new IMogoIntentListener() {
@Override
@@ -596,10 +583,10 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
};
public void startToRouteAndWipe(List<MessagePad.Location> models) {
List<LatLng> latLngModels = CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjListCommon(mContext,models);
List<Location> locationsModels = CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjLocations(mContext,models);
mLocationsModels.clear();
mLocationsModels.addAll(latLngModels);
mLocationsModels.addAll(locationsModels);
startOrStopRouteAndWipe(true);
showRottingMapView();
}
@@ -622,7 +609,6 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
NaviLatLng endNaviLatLng = new NaviLatLng(orderEndStationLat,orderEndStationLng);
AmapNaviToDestinationModel.getInstance(mContext).initAMapNavi(startNaviLatLng, endNaviLatLng);
AmapNaviToDestinationModel.getInstance(mContext).setVoiceIsMute(false);
// AmapNaviToDestinationModel.getInstance(mContext).setOCHTaciNaviChangedCallback(this);
}
}
@@ -641,9 +627,16 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
public void loopRouteAndWipe() {
if (mLocationsModels != null && mLocationsModels.size() > 0){
int haveArrivedIndex = CoordinateCalculateRouteUtil
.getArrivedPointIndex(mLocationsModels,mLongitude,mLatitude);
.getArrivedPointIndexNew(mPreRouteIndex,
mLocationsModels,
mLongitude,
mLatitude);
mPreRouteIndex = haveArrivedIndex;
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.routeResultByServer(mLocationsModels,haveArrivedIndex);
List<LatLng> latLngsModels = CoordinateCalculateRouteUtil
.coordinateConverterLocationToLatLng(mContext,
mLocationsModels);
mAutopilotPlanningCallback.routeResultByServer(latLngsModels,haveArrivedIndex);
}
}
}
@@ -731,7 +724,9 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback
mAutopilotPlanningCallback.setLineMarker(data.data);
}
mLocationsModels.clear();
mLocationsModels.addAll(data.data);
List<Location> locationsModels = CoordinateCalculateRouteUtil.
coordinateConverterLatlngToLocation(data.data);
mLocationsModels.addAll(locationsModels);
startOrStopRouteAndWipe(true);
}
}else {

View File

@@ -86,6 +86,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.functions.Consumer;
@@ -127,9 +128,11 @@ public class TaxiModel {
private volatile boolean isRestartAutopilot = false;
private List<LatLng> mRoutePoints = new ArrayList<>();
private List<Location> mRoutePoints = new ArrayList<>();
private int mPreRouteIndex = 0;
private double mLongitude, mLatitude;
private Location mLocation = null;
private LoginService loginService;
@@ -737,8 +740,8 @@ public class TaxiModel {
public void confirmAutopilotConditionByDriver() {
if (mCurrentOCHOrder == null) return;
TaxiOrPassengerReadyReqBean.Result result = new TaxiOrPassengerReadyReqBean.Result();
result.lat = mLatitude;
result.lon = mLongitude;
// result.lat = mLatitude;
// result.lon = mLongitude;
TaxiServiceManager.confirmAutopilotConditionByDriver(mContext,
mCurrentOCHOrder.orderNo,
result,
@@ -1064,6 +1067,7 @@ public class TaxiModel {
mLongitude = location.getLongitude();
mLatitude = location.getLatitude();
mLocation = location;
if (mControllerStatusCallback != null) {
mControllerStatusCallback.onCarLocationChanged(location);
}
@@ -1333,7 +1337,8 @@ public class TaxiModel {
if (mRoutePoints.size() > 0){
mRoutePoints.clear();
}
mRoutePoints.addAll(CoordinateCalculateRouteUtil.coordinateConverterWgsToGcjListCommon(mContext, models));
mRoutePoints.addAll(CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjLocations(mContext, models));
startDynamicCalculateRouteInfo();
}
@@ -1367,47 +1372,57 @@ public class TaxiModel {
* 实时计算当前剩余里程和时间
*/
public void dynamicCalculateRouteInfo() {
if (mLatitude <= 0.0 || mLongitude <= 0.0){
if (mLocation == null){
return;
}
if (mRoutePoints.size() > 0){
List<LatLng> lastPoints = CoordinateCalculateRouteUtil
.getRemainPointListByCompare(mRoutePoints, mLongitude, mLatitude);
if (mRoutePoints.size() > 0 && mLocation != null){
Map<Integer,List<Location>> lastPointsMap = CoordinateCalculateRouteUtil
.getRemainPointListByCompareNew(mPreRouteIndex,mRoutePoints, mLocation);
float lastSumLength = 0;
if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离
lastSumLength = CoordinateUtils.calculateLineDistance(
lastPoints.get(0).longitude, lastPoints.get(0).latitude,
mLongitude, mLatitude);
} else {
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
for (int index: lastPointsMap.keySet()) {
mPreRouteIndex = index;
break;
}
for (List<Location> lastPoints: lastPointsMap.values()){
float lastSumLength = 0;
if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离
lastSumLength = CoordinateUtils.calculateLineDistance(
lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(),
mLocation.getLongitude(), mLocation.getLatitude());
} else {
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
}
double lastTime = lastSumLength / TaxiConst.TAXI_AVERAGE_SPEED * 3.6; //秒
CallerLogger.INSTANCE.d(M_TAXI + "dynamicCalculateRouteInfo"
, "---lastSumLength: " + lastSumLength + "----lastTime : " + lastTime
+ " thread = "+ Thread.currentThread().getName());
double lastTime = lastSumLength / TaxiConst.TAXI_AVERAGE_SPEED * 3.6; //秒
CallerLogger.INSTANCE.d(M_TAXI + "dynamicCalculateRouteInfo"
, "---lastSumLength: " + lastSumLength + "----lastTime : " + lastTime
+ " thread = "+ Thread.currentThread().getName());
mCurrentOCHOrder.decreaseTravelDistance(lastSumLength);
if (mOrderStatusCallback != null) {
mOrderStatusCallback.onCurrentOrderDistToEndChanged((long) lastSumLength, (long) lastTime);
mCurrentOCHOrder.decreaseTravelDistance(lastSumLength);
if (mOrderStatusCallback != null) {
mOrderStatusCallback.onCurrentOrderDistToEndChanged((long) lastSumLength, (long) lastTime);
}
reportOrderRemain((long) lastSumLength, (long) lastTime);
break;
}
reportOrderRemain((long) lastSumLength, (long) lastTime);
routeAndWipe();
}
}
private void routeAndWipe() {
if (mRoutePoints != null && mRoutePoints.size() > 0){
if (mRoutePoints != null && mRoutePoints.size() > 0 && mLocation != null){
int haveArrivedIndex = CoordinateCalculateRouteUtil
.getArrivedPointIndex(mRoutePoints,mLongitude,mLatitude);
.getArrivedPointIndexNew(mPreRouteIndex,
mRoutePoints,
mLocation.getLongitude(),
mLocation.getLatitude());
List<LatLng> routePoints = CoordinateCalculateRouteUtil
.coordinateConverterLocationToLatLng(mContext,mRoutePoints);
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.routeResult(mRoutePoints,haveArrivedIndex);
mAutopilotPlanningCallback.routeResult(routePoints,haveArrivedIndex);
}
setRouteLineMarker(mRoutePoints);
setRouteLineMarker(routePoints);
}
}
@@ -1422,7 +1437,9 @@ public class TaxiModel {
public void onSuccess(QueryOrderRouteResp data) {
if (data != null && data.data != null && mRoutePoints.size() == 0) {
mRoutePoints.clear();
mRoutePoints.addAll(data.data);
List<Location> routePoints = CoordinateCalculateRouteUtil
.coordinateConverterLatlngToLocation(data.data);
mRoutePoints.addAll(routePoints);
}
}