xuhy
2026-04-17 4edaaf570a2cd8af8a9c35694a46289cdf9278b3
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/GDMapGeocodingUtil.java
@@ -10,6 +10,7 @@
import com.xiaopeng.map.mangodb.service.XpGeoFencingPolygonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -17,8 +18,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;
/**
 * 高德地图的地理编码工具类
@@ -35,20 +36,18 @@
    private XpGeoFencingPolygonService xpGeoFencingPolygonService;
    /**
     * 根据起始点获取驾车距离 和 时间  以及避让区域
     *
     * @param start 起点
     * @param end 终点
     * @param avoidRoads 避让点
     * @param fenceId mango id
     * @param start         起点
     * @param end           终点
     * @param avoidRoads    避让点
     * @param fenceId       mango id
     * @param routePlanRule 线路规划规则
     *
     * @return
     * @throws Exception
     */
    public RouteVo getDistanceAndTime(LonLatDto start, LonLatDto end,String avoidRoads,String fenceId,Integer routePlanRule, List<HistoryPointDto> history)  {
    public RouteVo getDistanceAndTime(LonLatDto start, LonLatDto end,ArrayList<JSONObject> avoidRoads,String fenceId,Integer routePlanRule, List<HistoryPointDto> history)  {
        RouteVo routeVo = new RouteVo();
        String url = "https://tsapi.amap.com/v1/route/price?key=" + key + "&extensions=all&start=" + start.getLongitude() + "," + start.getLatitude();
@@ -56,20 +55,20 @@
        params.put("extensions", "all");
        params.put("start", start.getLongitude() + "," + start.getLatitude());
        params.put("end", end.getLongitude() + "," + end.getLatitude());
        params.put("routeUserType",2);
        if(avoidRoads!=null && !avoidRoads.isEmpty()){
            params.put("voidPolygons", avoidRoads);
        params.put("routeUserType", 2);
        if (avoidRoads != null && !avoidRoads.isEmpty()) {
            params.put("avoidPolygons", avoidRoads);
        }
        if(routePlanRule!=null){
        if (routePlanRule != null) {
            params.put("strategy", routePlanRule);
        }
        if(null != history && !history.isEmpty()){
            params.put("history", history);
        }
        log.info("高德地图接口:{}", url);
        log.info("高德地图参数:{}", params);
        log.info("高德地图参数:{}", JSON.toJSONString(params));
        String post = HttpUtils.post(url, JSON.toJSONString(params));
        log.info("高德地图返回结果:"+ post);
        log.info("高德地图返回结果:" + post);
        JSONObject jsonObject = JSON.parseObject(post);
        String data = jsonObject.getString("data");
@@ -133,7 +132,7 @@
            ArrayPointsTask arrayPointsTask = new ArrayPointsTask(pointsArray, fenceId); // 创建求和任务对象并传入数组作为参数(这里也可以传入数组的一部分作为参数来实现更细粒度的拆分)
            Long temp = pool.invoke(arrayPointsTask); // 提交任务并等待处理完成(也可以使用submit方法提交任务并获取一个Future对象来异步获取结果)
            pool.shutdown(); // 关闭ForkJoinPool(释放资源)
            if(temp==0){
            if (temp == 0) {
                Integer costTime = jsonObject2.getInteger("costTime");
                Integer distance = jsonObject2.getInteger("distance");
                routeVo.setDistance(distance);
@@ -156,23 +155,22 @@
    public static void main(String[] args) {
        String url = "https://tsapi.amap.com/v1/route/price?key=" + "66ae577f63898dae3016d599fda57221" + "&extensions=all&start=" +"113.384932" + "," + "23.155455";
        String url = "https://tsapi.amap.com/v1/route/price?key=" + "66ae577f63898dae3016d599fda57221" + "&extensions=all&start=" + "113.384932" + "," + "23.155455";
        HashMap<String, Object> params = new HashMap<>();
        params.put("extensions", "all");
        params.put("start", "113.384932" + "," + "23.155455");
        params.put("end", "113.388209" + "," + "23.163455");
        params.put("routeUserType",2);
        params.put("routeUserType", 2);
        log.info("高德地图接口:{}", url);
        log.info("高德地图参数:{}", params);
        String post = HttpUtils.post(url, JSON.toJSONString(params));
        log.info("高德地图返回结果:"+ post);
        log.info("高德地图返回结果:" + post);
        JSONObject jsonObject = JSON.parseObject(post);
        System.out.println(jsonObject);
    }
    class ArrayPointsTask extends RecursiveTask<Long>{
    class ArrayPointsTask extends RecursiveTask<Long> {
        //最大定位集合阈值
        private final int THRESHOLD = 10;
        //围栏ID
@@ -188,14 +186,14 @@
        @Override
        protected Long compute() {
            if(this.pointsArray.size() > THRESHOLD){
            if (this.pointsArray.size() > THRESHOLD) {
                int num = this.pointsArray.size() / 2;
                ArrayPointsTask task1 = new ArrayPointsTask(this.pointsArray.subList(0, num), fenceId);
                ArrayPointsTask task2 = new ArrayPointsTask(this.pointsArray.subList(num, this.pointsArray.size()), fenceId);
                task1.fork();
                task2.fork();
                return task1.join() + task2.join();
            }else{
            } else {
                long temp = 0;
                for (LonLatDto lonLatDto : this.pointsArray) {
                    if (!xpGeoFencingPolygonService.isInFence(lonLatDto.getLongitude(), lonLatDto.getLatitude(), fenceId, "operating_area")) {
@@ -209,28 +207,29 @@
    }
    /**
     * 线路还原接口
     * 车端使用的数据
     *
     * @param routeID
     * @return
     */
    public String routed(String routeID){
    public String routed(String routeID) {
        String url = "https://tsapi.amap.com/v1/route/query/routeid?key=" + key;
        HashMap<String, Object> params = new HashMap<>();
        params.put("routeID", routeID);
        params.put("sdkVersion", "9.850.152.3.532");
        params.put("encoderVersion", "5.1");
        params.put("pushDataNaviVersion", "1.0");
        String post = HttpUtils.post(url, JSON.toJSONString(params));
        log.info("高德地图返回结果:"+ post);
        log.info("高德地图: routeId:{} 结果: {}", routeID, post);
        return post;
    }
    /**
     * 根据经纬度获取行政区域信息
     *
     * @param lon
     * @param lan
     * @return
@@ -241,7 +240,7 @@
        String forObject = HttpUtils.sendGet(url);
        JSONObject jsonObject = JSON.parseObject(forObject);
        Map<String, String> map = new HashMap<>();
        if(jsonObject.getString("status").equals("1")){
        if (jsonObject.getString("status").equals("1")) {
            JSONObject regeocode = jsonObject.getJSONObject("regeocode");
            JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
            String address = regeocode.getString("formatted_address");