From 36cecbaaba994d398485d5402d35273349c02be2 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Fri, 25 Nov 2022 17:34:28 +0800 Subject: [PATCH] =?UTF-8?q?[2.13.0]=20taxi/bus=20=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/model/BusPassengerModel.java | 76 +++++--- .../ui/BusPassengerMapDirectionView.java | 15 +- .../utils/CoordinateCalculateRouteUtil.java | 166 ++++++++---------- .../passenger/model/TaxiPassengerModel.java | 41 ++--- .../com/mogo/och/taxi/model/TaxiModel.java | 79 +++++---- 5 files changed, 193 insertions(+), 184 deletions(-) diff --git a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java index 9576b73da4..9a25f2e312 100644 --- a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java +++ b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java @@ -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 mRoutePoints = new ArrayList<>(); + private List 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 mStations = new ArrayList<>(); private int mNextStationIndex = 0;// 要到达站的index - private List mTwoStationsRouts = new ArrayList<>(); + private List 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 routePoints){ mRoutePoints.clear(); - List latLngModels = CoordinateCalculateRouteUtil - .coordinateConverterWgsToGcjListCommon(mContext,routePoints); + List 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 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> 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 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 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 routePoints = CoordinateCalculateRouteUtil + .coordinateConverterLocationToLatLng(mContext,mRoutePoints); + mAutopilotPlanningCallback.setLineMarker(routePoints); } } diff --git a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java index a0fc02d3cf..509f908434 100644 --- a/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java +++ b/OCH/mogo-och-bus-passenger/src/main/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java @@ -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)); -// } + } } diff --git a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/utils/CoordinateCalculateRouteUtil.java b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/utils/CoordinateCalculateRouteUtil.java index 3ab7e47426..879a69086e 100644 --- a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/utils/CoordinateCalculateRouteUtil.java +++ b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/utils/CoordinateCalculateRouteUtil.java @@ -21,20 +21,36 @@ import mogo.telematics.pad.MessagePad; */ public class CoordinateCalculateRouteUtil { - public static float calculateRouteSumLength(List points){ + public static float calculateRouteSumLength(List 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 getCurrentPoinByCompare(List 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 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 coordinateConverterLocationToLatLng(Context mContext, List models) { + //转成MogoLatLng集合 + List 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> getRemainPointListByCompareNew(int preIndex, List mRoutePoints, Location realLocation) { - Map> routePonits = new HashMap<>(); - List latePoints = new ArrayList<>(); // 剩余轨迹集合 + Map> routePonits = new HashMap<>(); + List 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 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 mRoutePoints, - Location realLocation) { - int currentIndex = 0; //记录疑似点 //基础点 + public static int getArrivedPointIndexNew(int preIndex, List 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; diff --git a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java index a25cc52a39..c1fddf11d7 100644 --- a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java +++ b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java @@ -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 mLocationsModels = new ArrayList<>(); + private List 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 models) { - List latLngModels = CoordinateCalculateRouteUtil - .coordinateConverterWgsToGcjListCommon(mContext,models); + List 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 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 locationsModels = CoordinateCalculateRouteUtil. + coordinateConverterLatlngToLocation(data.data); + mLocationsModels.addAll(locationsModels); startOrStopRouteAndWipe(true); } }else { diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java index da35077c43..715e9d2d7e 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java @@ -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 mRoutePoints = new ArrayList<>(); + private List 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 lastPoints = CoordinateCalculateRouteUtil - .getRemainPointListByCompare(mRoutePoints, mLongitude, mLatitude); + if (mRoutePoints.size() > 0 && mLocation != null){ + Map> 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 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 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 routePoints = CoordinateCalculateRouteUtil + .coordinateConverterLatlngToLocation(data.data); + mRoutePoints.addAll(routePoints); } }