[charter]
[3.2.0] [精确计算当前位置距离站点的距离]
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -70,6 +70,104 @@ public class CoordinateCalculateRouteUtil {
|
||||
return sumLength;
|
||||
}
|
||||
|
||||
public static float calculateRouteSumLength(List<MogoLocation> 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<MogoLocation> 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<LatLng> coordinateConverterWgsToGcjListCommon(Context mContext, List<MessagePad.Location> models) {
|
||||
//转成MogoLatLng集合
|
||||
List<LatLng> list = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user