[2.12.0] common 增加轨迹计算新方法代码(暂不用)
This commit is contained in:
@@ -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<Location> 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<Location> coordinateConverterWgsToGcjLocations(Context mContext, List<MessagePad.Location> models) {
|
||||
//转成MogoLatLng集合
|
||||
List<Location> 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<Integer,List<LatLng>> getRemainPointListByCompareNew(int preIndex,
|
||||
List<Location> mRoutePoints,
|
||||
Location realLocation) {
|
||||
Map<Integer,List<LatLng>> routePonits = new HashMap<>();
|
||||
List<LatLng> 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<Location> 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<Location> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user