From 73b750200f25df08aa64124da49e7461f9de6653 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 13 十二月 2024 15:09:49 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/NTTravel

---
 UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/AmapGeocoding.java |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/AmapGeocoding.java b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/AmapGeocoding.java
index b4df786..896cc76 100644
--- a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/AmapGeocoding.java
+++ b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/AmapGeocoding.java
@@ -61,6 +61,7 @@
         JSONObject jsonObject = new JSONObject(response.toString());
         if ("1".equals(jsonObject.getString("status"))) {
             JSONObject regeocode = jsonObject.getJSONObject("regeocode");
+            String regeocodesss = regeocode.getString("formatted_address");
             JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
             String cityName = addressComponent.getString("city"); // 这里改为了获取城市名称
             return cityName;
@@ -71,6 +72,37 @@
 
 
 
+    public static String getAddress(double latitude, double longitude) throws Exception {
+        String url = AMAP_GEOCODING_API + "?location=" + longitude + "," + latitude
+                + "&output=json&key=" + AMAP_KEY + "&radius=1000&extensions=all";
+
+        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+        connection.setRequestMethod("GET");
+        connection.connect();
+
+        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+        StringBuilder response = new StringBuilder();
+        String line;
+        while ((line = reader.readLine()) != null) {
+            response.append(line);
+        }
+        reader.close();
+        connection.disconnect();
+
+        JSONObject jsonObject = new JSONObject(response.toString());
+        if ("1".equals(jsonObject.getString("status"))) {
+            JSONObject regeocode = jsonObject.getJSONObject("regeocode");
+            String regeocodesss = regeocode.getString("formatted_address");
+            JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
+            String cityName = addressComponent.getString("city"); // 这里改为了获取城市名称
+            return regeocodesss;
+        } else {
+            throw new RuntimeException("Failed to fetch city name. Error message: " + jsonObject.getString("info"));
+        }
+    }
+
+
+
     public static void main(String[] args) throws Exception {
         double lat = 116.3913; // 纬度
         double lng = 39.90539; // 经度

--
Gitblit v1.7.1