无关风月
2025-02-08 1f41490f50b3861f68e54cd8aebee37549bab3eb
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapElectricFenceUtil.java
@@ -33,7 +33,7 @@
    @Autowired
    private IGDInterfaceService gdInterfaceService;
    private String key = "5053ca611c0106e01a665ce7ab84ff26";
    private String key = "WQhfsluNzEeUHUxoH4jc4JiCQOXw4Mnx";
    private JSONArray jsonArray = new JSONArray();
@@ -351,20 +351,21 @@
     * @return
     */
    public Map<String, String> getDistance(String origins, String destination, Integer type){
        String url = "https://restapi.amap.com/v3/distance?key=" + key + "&origins=" + origins + "&destination=" + destination +
                "&type=" + type;
        String url = "https://api.map.baidu.com/directionlite/v1/driving?origin="+origins+"&destination="+destination+"&ak="+key;
        String forObject = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSON.parseObject(forObject);
        System.err.println("获取距离"+jsonObject);
        String status = jsonObject.getString("status");
//        gdInterfaceService.saveData("https://restapi.amap.com/v3/distance", "查询两点间的距离");
        if(status.equals("1")){
            JSONArray results = jsonObject.getJSONArray("results");
        if(status.equals("0")){
            JSONObject result = jsonObject.getJSONObject("result");
            JSONArray results = result.getJSONArray("routes");
            System.err.println("路线数组"+results);
            JSONObject jsonObject1 = results.getJSONObject(0);
            Map<String, String> map = new HashMap<>();
            map.put("distance", jsonObject1.getString("distance"));//距离(米)
            map.put("duration", jsonObject1.getString("duration"));//预计时间(秒)
            System.err.println("返回map");
            return map;
        }else{
            System.err.println(forObject);
@@ -372,7 +373,37 @@
        return null;
    }
    /**
     * 根据经纬度获取行政区域信息
     *
     * @param lon
     * @param lan
     * @return
     * @throws Exception
     */
    public Map<String, String> geocode(String lon, String lan) throws Exception {
        String url = "https://api.map.baidu.com/reverse_geocoding/v3/?ak=" + key + "&output=json&coordtype=bd09ll" + "&location=" + lan + "," + lon;
        String forObject = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSON.parseObject(forObject);
        Map<String, String> map = new HashMap<>();
        if (jsonObject.getString("status").equals("0")) {
            JSONObject result = jsonObject.getJSONObject("result");
            JSONObject addressComponent = result.getJSONObject("addressComponent");
            String address = result.getString("formatted_address");
            map.put("address", address);
            String code = addressComponent.getString("adcode");
            String province = addressComponent.getString("province");
            String city = addressComponent.getString("city");
            String district = addressComponent.getString("district");
            map.put("province", province);
            map.put("provinceCode", code.substring(0, 2) + "0000");
            map.put("city", city);
            map.put("cityCode", code.substring(0, 4) + "00");
            map.put("district", district);
            map.put("districtCode", code);
        }
        return map;
    }
    /**
     * 获取路径规划
     * @param origins       起点坐标