From bd8612a00027f2e635d7765565989d48c5d96464 Mon Sep 17 00:00:00 2001 From: yangyakun Date: Mon, 20 Mar 2023 11:26:08 +0800 Subject: [PATCH] =?UTF-8?q?[m1]=20[=E8=AE=A1=E7=AE=97=E5=89=A9=E4=BD=99?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E4=BC=98=E5=8C=96]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/model/CharterPassengerModel.kt | 91 +++++++++++++------ 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/OCH/mogo-och-charter-passenger/src/m1/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt b/OCH/mogo-och-charter-passenger/src/m1/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt index fedfe4f303..cf44b22aa5 100644 --- a/OCH/mogo-och-charter-passenger/src/m1/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt +++ b/OCH/mogo-och-charter-passenger/src/m1/java/com/mogo/och/bus/passenger/model/CharterPassengerModel.kt @@ -626,43 +626,82 @@ object CharterPassengerModel { private fun calculateDistance() { //mLocation gcj坐标 mLocationGCJ02?.let { - // 启动轨迹计算 - //当前站在轨迹中对应的点 - val currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew( - 0, mRoutePoints, it.longitude, it.latitude - ) - //要前往的站在轨迹中对应的点 - var nextRouteIndex: Int = mRoutePoints.size - 1 - orderInfo?.let {order-> - val coordinateConverterWgsToGcj = + var lastSumLength = 0f + orderInfo?.let { order -> + // 启动轨迹计算 + //当前站在轨迹中对应的点 + val currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew( + 0, mRoutePoints, it.longitude, it.latitude + ) + var nextRouteIndex: Int = mRoutePoints.size - 1 + + val orderLonLat = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj( mContext, order.wgs84Lon!!, order.wgs84Lat!! ) + //要前往的站在轨迹中对应的点 nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew( currentRouteIndex, mRoutePoints, - coordinateConverterWgsToGcj.longitude, - coordinateConverterWgsToGcj.latitude + orderLonLat.longitude, + orderLonLat.latitude ) - } - var lastSumLength = 0f - if (currentRouteIndex < nextRouteIndex) { - // subList 是[) 需要的是[] - val subList = mRoutePoints.subList(currentRouteIndex, nextRouteIndex+1) - val middlePoingDistancee = - CoordinateCalculateRouteUtil.calculateRouteSumLength(subList) - val lastPoints = mRoutePoints.get(currentRouteIndex) - lastSumLength = CoordinateUtils.calculateLineDistance( - lastPoints.longitude, lastPoints.latitude, - it.longitude, it.latitude - ) + middlePoingDistancee - } else { + // 距离站点最近的轨迹点 val lastPoints = mRoutePoints.get(nextRouteIndex) - lastSumLength = CoordinateUtils.calculateLineDistance( + // 站点距离最近点的距离 + val calculateLineDistance = CoordinateUtils.calculateLineDistance( lastPoints.longitude, lastPoints.latitude, - it.longitude, it.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 (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 //秒