无关风月
2025-01-16 34e04f768d578c861daa7d4071d07cf3bdae9120
补充
1个文件已修改
46 ■■■■■ 已修改文件
ManagementOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ManagementOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java
@@ -45,21 +45,18 @@
            return map;
        }
        String url = "https://restapi.amap.com/v3/geocode/geo?key=" + key + "&output=JSON";
        String url = "https://api.map.baidu.com/geocoding/v3/"+"?output=json&ak=" +key+"&ret_coordtype="+"bd09ll";
        url += "&address=" + (ToolUtil.isNotEmpty(province) ? province : "") + (ToolUtil.isNotEmpty(city) ? city : "") + (ToolUtil.isNotEmpty(county) ? county : "") + address;
        String forObject = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSON.parseObject(forObject);
        String status = jsonObject.getString("status");
        List<String> list = new ArrayList<>();
        gdInterfaceService.saveData("https://restapi.amap.com/v3/geocode/geo", "行政区域转经纬度");
        if(status.equals("1")){
            JSONArray geocodes = jsonObject.getJSONArray("geocodes");
            for(int i = 0; i < geocodes.size(); i++){
                String location = geocodes.getJSONObject(i).getString("location");
                list.add(location);
            }
        if(status.equals("0")){
            JSONObject result = jsonObject.getJSONObject("result");
            JSONObject location = result.getJSONObject("location");
            String lng = location.getString("lng");
            String lat = location.getString("lat");
            list.add(lat+","+lng);
        }
        map.put("status", 0);
        map.put("data", list);
@@ -70,20 +67,17 @@
    public Map<String, Object> geocoding(String address){
        Map<String, Object> map = new HashMap<>();
        String url = "https://restapi.amap.com/v3/geocode/geo?key=" + key + "&output=JSON&address=" + address;
        String url = "https://api.map.baidu.com/geocoding/v3/?address"+ address+"&output=json&ak=" +key+"&ret_coordtype="+"bd09ll";
        String forObject = restTemplate.getForObject(url, String.class);
        JSONObject jsonObject = JSON.parseObject(forObject);
        String status = jsonObject.getString("status");
        List<String> list = new ArrayList<>();
        gdInterfaceService.saveData("https://restapi.amap.com/v3/geocode/geo", "行政区域转经纬度");
        if(status.equals("1")){
            JSONArray geocodes = jsonObject.getJSONArray("geocodes");
            for(int i = 0; i < geocodes.size(); i++){
                String location = geocodes.getJSONObject(i).getString("location");
                list.add(location);
            }
        if(status.equals("0")){
            JSONObject result = jsonObject.getJSONObject("result");
            JSONObject location = result.getJSONObject("location");
            String lng = location.getString("lng");
            String lat = location.getString("lat");
            list.add(lat+","+lng);
        }
        map.put("status", 0);
        map.put("data", list);
@@ -100,17 +94,17 @@
     * @throws Exception
     */
    public Map<String, String> geocode(String lon, String lan) throws Exception{
        String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan;
        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<>();
        gdInterfaceService.saveData("https://restapi.amap.com/v3/geocode/regeo", "经纬度转行政区域");
        gdInterfaceService.saveData("https://api.map.baidu.com/reverse_geocoding", "经纬度转行政区域");
        if(jsonObject.getString("status").equals("1")){
            JSONObject regeocode = jsonObject.getJSONObject("regeocode");
            JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
            String address = regeocode.getString("formatted_address");
        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");