package com.xiaopeng.order.utils;
|
|
import com.xiaopeng.order.mangodb.model.OrderTrajectory;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
public class TrajectoryGenerator {
|
|
// 成都市中心经纬度(示例)
|
private static final double BASE_LAT = 30.5728; // 纬度
|
private static final double BASE_LON = 104.0668; // 经度
|
|
/**
|
* 根据 GpsPoint 数据生成 OrderTrajectory 轨迹记录
|
*
|
* @param gpsPoints 模拟的 GpsPoint 数据
|
* @return 轨迹记录列表
|
*/
|
public static List<OrderTrajectory> generateTrajectory(List<TaxiPricingDemoService.GpsPoint> gpsPoints) {
|
List<OrderTrajectory> trajectories = new ArrayList<>();
|
|
// 初始位置
|
double currentLat = BASE_LAT;
|
double currentLon = BASE_LON;
|
|
for (int i = 0; i < gpsPoints.size(); i++) {
|
TaxiPricingDemoService.GpsPoint point = gpsPoints.get(i);
|
|
// 生成随机偏移量(确保相邻点距离不超过100米)
|
double deltaLat = (Math.random() - 0.5) * 0.001; // 纬度偏移
|
double deltaLon = (Math.random() - 0.5) * 0.001; // 经度偏移
|
|
// 更新当前位置
|
currentLat += deltaLat;
|
currentLon += deltaLon;
|
|
// 创建 OrderTrajectory 对象
|
OrderTrajectory trajectory = new OrderTrajectory();
|
trajectory.setOrderId(1L); // 假设订单 ID 为 1
|
trajectory.setLocation(String.format("%.6f,%.6f", currentLon, currentLat)); // 经纬度格式化
|
trajectory.setDirection((int) (Math.random() * 360)); // 随机方向角
|
trajectory.setSpeed(Math.random() * 50); // 随机速度(0~50 km/h)
|
trajectory.setLocatetime(point.getLocatetime()); // 时间戳
|
trajectory.setDistance(point.getDistance()); // 距离
|
|
trajectories.add(trajectory);
|
}
|
|
return trajectories;
|
}
|
|
|
}
|