From 022edb39b6cc4122f80b6710e722263dfdc5d6ca Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Tue, 25 Oct 2022 17:33:41 +0800 Subject: [PATCH] =?UTF-8?q?[2.12.0]=20common=20=E5=A2=9E=E5=8A=A0=E8=BD=A8?= =?UTF-8?q?=E8=BF=B9=E8=AE=A1=E7=AE=97=E6=96=B0=E6=96=B9=E6=B3=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=88=E6=9A=82=E4=B8=8D=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/CoordinateCalculateRouteUtil.java | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) 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 d0532ffea9..2f092a2c47 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 @@ -1,6 +1,7 @@ package com.mogo.och.common.module.utils; import android.content.Context; +import android.location.Location; import com.amap.api.maps.CoordinateConverter; import com.amap.api.maps.model.LatLng; @@ -8,7 +9,9 @@ import com.mogo.cloud.commons.utils.CoordinateUtils; import com.mogo.eagle.core.utilcode.mogo.logger.Logger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import mogo.telematics.pad.MessagePad; @@ -202,4 +205,108 @@ public class CoordinateCalculateRouteUtil { } return currentIndex; } + + public static float calculateRouteSumLengthByLocation(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).getLatitude(); + double preLon = points.get(i).getLongitude(); + double laLat = points.get(i+1).getLatitude(); + double laLon = points.get(i+1).getLongitude(); + + float length = CoordinateUtils.calculateLineDistance(laLon,laLat,preLon,preLat); + sumLength += length; + } + return sumLength; + } + + + public static List coordinateConverterWgsToGcjLocations(Context mContext, List models) { + //转成MogoLatLng集合 + List list = new ArrayList<>(); + for (MessagePad.Location m : models) { + LatLng mogoLatLng = coordinateConverterWgsToGcj(mContext, m); + Location location = new Location("gcj_provider"); + location.setBearing((float) m.getHeading()); + location.setLatitude(mogoLatLng.latitude); + location.setLongitude(mogoLatLng.longitude); + list.add(location); + } + return list; + } + + public static Map> getRemainPointListByCompareNew(int preIndex, + List mRoutePoints, + Location realLocation) { + Map> routePonits = new HashMap<>(); + List latePoints = new ArrayList<>(); // 剩余轨迹集合 + int currentIndex = 0; //记录疑似点 + if (mRoutePoints.size() > preIndex){ + //基础点 + Location baseLatLng = mRoutePoints.get(preIndex); + float baseDiffDis = CoordinateUtils.calculateLineDistance(realLocation.getLongitude(), + realLocation.getLatitude() + ,baseLatLng.getLongitude(),baseLatLng.getLongitude());// lon,lat, prelon, prelat + + for (int i= preIndex; 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(), + latLng.getLongitude(),latLng.getLatitude()); + if (baseDiffDis > diff ){ +// Logger.d(M_TAXI + "calculateRouteSumLength", "点:"+i+"-------先记录点----- "); + baseDiffDis = diff; + currentIndex = i; + } + } + } + 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); + }else { + List locations = mRoutePoints.subList(currentIndex,mRoutePoints.size()-1); + for (Location location: locations) { + LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); + latePoints.add(latLng); + } + } + routePonits.put(currentIndex,latePoints); + return routePonits; + } + return routePonits; + } + + public static int getArrivedPointIndexNew(List mRoutePoints, + Location realLocation) { + int currentIndex = 0; //记录疑似点 //基础点 + Location baseLatLng = mRoutePoints.get(0); + float baseDiffDis = CoordinateUtils.calculateLineDistance(realLocation.getLongitude(), + realLocation.getLatitude() + , 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(), + latLng.getLongitude(), latLng.getLatitude()); + if (baseDiffDis > diff) { +// Logger.d(M_TAXI + "calculateRouteSumLength", "点:"+i+"-------先记录点----- "); + baseDiffDis = diff; + currentIndex = i; + } + } + } + Logger.d("calculateRouteSumLength", "点:" + currentIndex + "-------是最近的点------ "); + return currentIndex; + } }