订单轨迹回放

This commit is contained in:
19173159168
2025-10-18 23:26:07 +08:00
parent e4b06b1158
commit 4277fa880c
2 changed files with 50 additions and 1 deletions

View File

@ -35,4 +35,46 @@ public class CoordinateTransformUtil {
return ret;
}
/**
* WGS84坐标系转换为GCJ-02坐标系
* @param wgsLat WGS84纬度
* @param wgsLng WGS84经度
* @return GCJ-02坐标 [纬度, 经度]
*/
public static double[] wgs84ToGcj02(double wgsLat, double wgsLng) {
double a = 6378245.0; // WGS 长轴半径
double ee = 0.00669342162296594323; // WGS 偏心率的平方
double dLat = transformLat(wgsLng - 105.0, wgsLat - 35.0);
double dLon = transformLon(wgsLng - 105.0, wgsLat - 35.0);
double radLat = wgsLat / 180.0 * Math.PI;
double magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Math.PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * Math.PI);
double gcjLat = wgsLat + dLat;
double gcjLng = wgsLng + dLon;
return new double[]{gcjLat, gcjLng};
}
private static double transformLat(double x, double y) {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
return ret;
}
private static double transformLon(double x, double y) {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;
return ret;
}
}

View File

@ -10,6 +10,7 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.operation.domain.Company;
import com.ruoyi.operation.service.ICompanyService;
import com.ruoyi.operation.util.CoordinateTransformUtil;
import com.ruoyi.orders.domain.ZcOrderCarChange;
import com.ruoyi.orders.dto.StatisticsHomeOrder;
import com.ruoyi.orders.dto.TrajectoryPoint;
@ -190,7 +191,13 @@ public class ZcOrderMainController extends BaseController
}
List<TrajectoryPoint> trajectoryPoints = dataPushApi.fetchOrderTrajectory(orderMain.getLotNumber(), startTm, endTm);
// 设置中心点和轨迹点列表
if (!trajectoryPoints.isEmpty()) {
// WGS84坐标转换为GCJ-02坐标腾讯地图使用
if (trajectoryPoints != null && !trajectoryPoints.isEmpty()) {
for (TrajectoryPoint point : trajectoryPoints) {
double[] gcj02 = CoordinateTransformUtil.wgs84ToGcj02(point.getLat(), point.getLng());
point.setLat(gcj02[0]); // 纬度
point.setLng(gcj02[1]); // 经度
}
mmap.put("centerPoint", trajectoryPoints.get(0));
mmap.put("orderTrajectoryPointList", trajectoryPoints);
mmap.put("orderTrajectoryPointLen", trajectoryPoints.size()-1);