liujie
2026-02-14 8b5ac6aa170ba050387c14931b95b9d9ce5ee4e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
    }
 
 
}