From 78b7d3eff32c692af222c1d5382a9c8e4bb8f77b Mon Sep 17 00:00:00 2001 From: yangyakun Date: Wed, 26 Apr 2023 14:36:02 +0800 Subject: [PATCH] =?UTF-8?q?[charter]=20[3.2.0]=20[=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=BD=93=E5=89=8D=E4=BD=8D=E7=BD=AE=E8=B7=9D?= =?UTF-8?q?=E7=A6=BB=E7=AB=99=E7=82=B9=E7=9A=84=E8=B7=9D=E7=A6=BB]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/model/CharterPassengerModel.kt | 87 ++++------------ .../utils/CoordinateCalculateRouteUtil.java | 98 +++++++++++++++++++ 2 files changed, 117 insertions(+), 68 deletions(-) diff --git a/OCH/mogo-och-charter-passenger/src/main/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt b/OCH/mogo-och-charter-passenger/src/main/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt index edcba59b1a..ed92ee8407 100644 --- a/OCH/mogo-och-charter-passenger/src/main/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt +++ b/OCH/mogo-och-charter-passenger/src/main/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt @@ -622,92 +622,43 @@ object CharterPassengerModel { private fun calculateDistance() { //mLocation gcj坐标 mLocationGCJ02?.let { - var lastSumLength = 0f orderInfo?.let { order -> // 启动轨迹计算 - //当前站在轨迹中对应的点 - val currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew( - 0, mRoutePoints, it.longitude, it.latitude - ) - var nextRouteIndex: Int = mRoutePoints.size - 1 - + var lastSumLength = 0f val orderLonLat = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj( mContext, order.wgs84Lon!!, order.wgs84Lat!! ) - //要前往的站在轨迹中对应的点 - nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew( - currentRouteIndex, mRoutePoints, + val mogoLocation = MogoLocation() + mogoLocation.longitude = orderLonLat.longitude + mogoLocation.latitude = orderLonLat.latitude + + lastSumLength = CoordinateUtils.calculateLineDistance( orderLonLat.longitude, - orderLonLat.latitude + orderLonLat.latitude, + mogoLocation.longitude, + mogoLocation.latitude ) - // 距离站点最近的轨迹点 - val lastPoints = mRoutePoints.get(nextRouteIndex) - // 站点距离最近点的距离 - val calculateLineDistance = CoordinateUtils.calculateLineDistance( - lastPoints.longitude, lastPoints.latitude, - orderLonLat.longitude, orderLonLat.latitude - ) - if (currentRouteIndex < nextRouteIndex) { - // subList 是[) 需要的是[] - val subList = mRoutePoints.subList(currentRouteIndex, nextRouteIndex + 1) - // 轨迹点所有的距离 - val middlePoingDistancee = - CoordinateCalculateRouteUtil.calculateRouteSumLength(subList) - - // 需要加距离 和下一个轨迹点成钝角 - if (nextRouteIndex + 1 < mRoutePoints.size) { - val lastPointsNext = mRoutePoints.get(nextRouteIndex + 1) - val degree = CoordinateCalculateRouteUtil.getDegree( - orderLonLat.longitude,orderLonLat.latitude, - lastPoints.longitude, lastPoints.latitude, - lastPointsNext.longitude, lastPointsNext.latitude, + if(lastSumLength>100) { + // 计算距离 + lastSumLength = + CoordinateCalculateRouteUtil.calculateRouteSumLength( + mRoutePoints, + it, + mogoLocation ) - if (degree > 90) { - lastSumLength = middlePoingDistancee + calculateLineDistance - } - } - // 需要减距离 和上一个轨迹点成钝角 - if (nextRouteIndex - 1 >= 0) { - val lastPointsPre = mRoutePoints.get(nextRouteIndex - 1) - val degree = CoordinateCalculateRouteUtil.getDegree( - orderLonLat.longitude,orderLonLat.latitude, - lastPoints.longitude, lastPoints.latitude, - lastPointsPre.longitude, lastPointsPre.latitude, - ) - if (degree > 90) { - lastSumLength = middlePoingDistancee - calculateLineDistance - } - } - - } else { - val lastPoints = mRoutePoints.get(nextRouteIndex) - lastSumLength = CoordinateUtils.calculateLineDistance( - lastPoints.longitude, lastPoints.latitude, - it.longitude, it.latitude - ) - } - // 距离小于100m 直接计算当前位置距离站点的距离 - if(lastSumLength<=100){ - lastSumLength = CoordinateUtils.calculateLineDistance( - orderLonLat.longitude, - orderLonLat.latitude, - it.longitude, - it.latitude - ) } - val lastTime: Double = lastSumLength / Charter_AVERAGE_SPEED * 3.6 //秒 + val lastTime: Double = lastSumLength / it.gnssSpeed * 3.6 //秒 - CallerLogger.d( - SceneConstant.M_BUS_P + "calculateDistance", + CallerLogger.d(M_BUS_P + "calculateDistance", "---lastSumLength: " + lastSumLength + "----lastTime : " + lastTime + " thread = " + Thread.currentThread().name ) if (lastSumLength < CharterPassengerConst.ARRIVE_AT_START_STATION_DISTANCE) { - CallerLogger.d(SceneConstant.M_BUS_P + TAG,"小于15米到站2") + CallerLogger.d(M_BUS_P + TAG,"小于15米到站2") arriveDest() return } 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 8e6fec362b..94761923fe 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 @@ -70,6 +70,104 @@ public class CoordinateCalculateRouteUtil { return sumLength; } + public static float calculateRouteSumLength(List mRoutePoints, MogoLocation location, MogoLocation station){ + if (null == mRoutePoints || mRoutePoints.size() == 0) return 0; + + float lastSumLength = 0f; + + //当前位置距离轨迹中最近的点 + int currentRouteIndex = getArrivedPointIndexNew( + 0, mRoutePoints, location.getLongitude(), location.getLatitude() + ); + // 距离当前位置轨迹中最近的轨迹点 + MogoLocation currentPoint = mRoutePoints.get(currentRouteIndex); + // 当前位置距离最近的点的距离 + float calculateCurrentdex = CoordinateUtils.calculateLineDistance( + location.getLongitude(), location.getLatitude(), + currentPoint.getLongitude(), currentPoint.getLatitude() + ); + + + //要前往的站在轨迹中对应的点 + int stationPointInRouteIndex = getArrivedPointIndexNew( + currentRouteIndex, mRoutePoints, + station.getLongitude(), + station.getLatitude() + ); + // 距离站点最近的轨迹点 + MogoLocation stationPointInRoute = mRoutePoints.get(stationPointInRouteIndex); + // 站点距离轨迹中最近点的距离 + float calculateLineDistance = CoordinateUtils.calculateLineDistance( + stationPointInRoute.getLongitude(), stationPointInRoute.getLatitude(), + station.getLongitude(), station.getLatitude() + ); + + if (currentRouteIndex < stationPointInRouteIndex) { + // subList 是[) 需要的是[] + List subList = mRoutePoints.subList(currentRouteIndex, stationPointInRouteIndex + 1); + // 轨迹点所有的距离 + lastSumLength = calculateRouteSumLength(subList); + // region 站点坐标和 站点坐标对应轨迹点的坐标距离 + // 需要加距离 和下一个轨迹点成钝角 + if (stationPointInRouteIndex + 1 < mRoutePoints.size()) { + MogoLocation lastPointsNext = mRoutePoints.get(stationPointInRouteIndex + 1); + double degree = getDegree( + station.getLongitude(),station.getLatitude(), + stationPointInRoute.getLongitude(), stationPointInRoute.getLatitude(), + lastPointsNext.getLongitude(), lastPointsNext.getLatitude()); + if (degree > 90) { + lastSumLength = lastSumLength + calculateLineDistance; + } + } + // 需要减距离 和上一个轨迹点成钝角 + if (stationPointInRouteIndex - 1 >= 0) { + MogoLocation lastPointsPre = mRoutePoints.get(stationPointInRouteIndex - 1); + double degree = getDegree( + station.getLongitude(),station.getLatitude(), + stationPointInRoute.getLongitude(), stationPointInRoute.getLatitude(), + lastPointsPre.getLongitude(), lastPointsPre.getLatitude()); + if (degree > 90) { + lastSumLength = lastSumLength - calculateLineDistance; + } + } + // endregion + + // region 当前位置和 对应轨迹点的坐标距离 + // 需要加距离 和下一个轨迹点成钝角 + if (currentRouteIndex + 1 < stationPointInRouteIndex) { + MogoLocation currentPointsNext = mRoutePoints.get(stationPointInRouteIndex + 1); + double degree = getDegree( + location.getLongitude(),location.getLatitude(), + currentPoint.getLongitude(), currentPoint.getLatitude(), + currentPointsNext.getLongitude(), currentPointsNext.getLatitude()); + if (degree > 90) { + lastSumLength = lastSumLength - calculateCurrentdex; + } + } + + // 需要减距离 和上一个轨迹点成钝角 + if (currentRouteIndex - 1 >= 0) { + MogoLocation lastPointsPre = mRoutePoints.get(stationPointInRouteIndex - 1); + double degree = getDegree( + location.getLongitude(),location.getLatitude(), + currentPoint.getLongitude(), currentPoint.getLatitude(), + lastPointsPre.getLongitude(), lastPointsPre.getLatitude()); + if (degree > 90) { + lastSumLength = lastSumLength + calculateCurrentdex; + } + } + // endregion + + } else { + MogoLocation lastPoints = mRoutePoints.get(stationPointInRouteIndex); + lastSumLength = CoordinateUtils.calculateLineDistance( + lastPoints.getLongitude(), lastPoints.getLatitude(), + location.getLongitude(), location.getLatitude() + ); + } + return lastSumLength; + } + public static List coordinateConverterWgsToGcjListCommon(Context mContext, List models) { //转成MogoLatLng集合 List list = new ArrayList<>();