From 26f9a13753471cef6e806305dd443afcb24e7052 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 16 一月 2025 21:15:22 +0800 Subject: [PATCH] 补充 --- UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java | 30 ++++++++++++++++++------------ 1 files changed, 18 insertions(+), 12 deletions(-) diff --git a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java index 3f83904..2b2aa08 100644 --- a/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java +++ b/UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GDMapGeocodingUtil.java @@ -80,22 +80,25 @@ public Map<String, Object> geocoding(String address){ Map<String, Object> map = new HashMap<>(); - String url = "https://api.map.baidu.com/geocoding/v3/?address"+ address+"&output=json&ak=" +key+"&ret_coordtype="+"bd09ll"; + String url = "https://restapi.amap.com/v3/geocode/geo?key=" + key + "&output=JSON&address=" + address; String forObject = restTemplate.getForObject(url, String.class); JSONObject jsonObject = JSON.parseObject(forObject); String status = jsonObject.getString("status"); List<String> list = new ArrayList<>(); - 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); + 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); + } } map.put("status", 0); map.put("data", list); return map; } + + + /** * 根据经纬度获取行政区域信息 * @param lon @@ -104,14 +107,17 @@ * @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 url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan; 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"); + +// gdInterfaceService.saveData("https://restapi.amap.com/v3/geocode/regeo", "经纬度转行政区域"); + + if(jsonObject.getString("status").equals("1")){ + JSONObject regeocode = jsonObject.getJSONObject("regeocode"); + JSONObject addressComponent = regeocode.getJSONObject("addressComponent"); + String address = regeocode.getString("formatted_address"); map.put("address", address); String code = addressComponent.getString("adcode"); String province = addressComponent.getString("province"); -- Gitblit v1.7.1