nickchange
2023-11-17 a9564eae9f0169ca39329b2f14a8f13d13358a0a
cloud-server-other/src/main/java/com/dsh/other/util/GDMapGeocodingUtil.java
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.dsh.other.util.httpClinet.HttpClientUtil;
import com.dsh.other.util.httpClinet.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -110,6 +111,7 @@
        JSONObject jsonObject = JSON.parseObject(httpResult.getData());
        Map<String, String> map = new HashMap<>();
        if(jsonObject.getString("status").equals("1")){
            JSONObject regeocode = jsonObject.getJSONObject("regeocode");
            JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
@@ -128,6 +130,37 @@
        }
        return map;
    }
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
    public Map<String, String> geocode1(String lon, String lan) throws Exception{
        String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan;
        HttpResult httpResult = HttpClientUtil.pushHttpRequset("GET", url, null, null, "json");
        JSONObject jsonObject = JSON.parseObject(httpResult.getData());
        Map<String, String> map = new HashMap<>();
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(lon, lan);
        String provinceCode = geocode.get("provinceCode");
        String cityCode = geocode.get("cityCode");
            map.put("cityCode", cityCode);
//        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");
//            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;
    }
    /**