From 21bd711a3756850299b443848181ee60708c6377 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 17 四月 2026 20:20:45 +0800
Subject: [PATCH] 代码生成

---
 server/services/src/main/java/com/doumee/core/utils/Tencent/MapUtil.java |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/utils/Tencent/MapUtil.java b/server/services/src/main/java/com/doumee/core/utils/Tencent/MapUtil.java
index cf377b8..9604686 100644
--- a/server/services/src/main/java/com/doumee/core/utils/Tencent/MapUtil.java
+++ b/server/services/src/main/java/com/doumee/core/utils/Tencent/MapUtil.java
@@ -28,6 +28,9 @@
     /** 璺濈鐭╅樀API */
     public static final String MATRIX_URL = "https://apis.map.qq.com/ws/distance/v1/matrix";
 
+    /** 閫嗗湴鐞嗚В鏋� */
+    public static final String GEO_URL = "https://apis.map.qq.com/ws/geocoder/v1/";
+
     /** 鏀寔鐨勬ā寮� */
     private static final List<String> SUPPORTED_MODES = Arrays.asList("driving", "bicycling");
 
@@ -121,4 +124,59 @@
                 .map(row -> ((JSONObject) row).getJSONArray("elements").getJSONObject(0))
                 .collect(Collectors.toList());
     }
+
+    /**
+     * 閫嗗湴鐞嗚В鏋� - 鏍规嵁缁忕含搴﹁幏鍙栧湴鍧�淇℃伅
+     *
+     * @param lat 绾害
+     * @param lng 缁忓害
+     * @return result.ad_info 涓殑 adcode(鍖哄垝鐮�)銆乧ity(鍩庡競)銆乨istrict(鍖�) 绛変俊鎭�
+     */
+    public static JSONObject reverseGeocode(double lat, double lng) {
+        try {
+            String url = GEO_URL
+                    + "?key=" + tencentKey
+                    + "&location=" + lat + "," + lng;
+
+            log.info("鑵捐鍦板浘閫嗗湴鐞嗚В鏋愯姹�: location={},{}", lat, lng);
+
+            JSONObject json = new Http().build(url)
+                    .setConnectTimeout(5000)
+                    .setReadTimeout(10000)
+                    .get()
+                    .toJSONObject();
+
+            log.info("鑵捐鍦板浘閫嗗湴鐞嗚В鏋愬搷搴�: {}", json);
+
+            if (json.getIntValue("status") != 0) {
+                throw new RuntimeException("鑵捐鍦板浘閫嗗湴鐞嗚В鏋愬け璐�: " + json.getString("message"));
+            }
+
+            return json.getJSONObject("result");
+        } catch (IOException e) {
+            log.error("鑵捐鍦板浘閫嗗湴鐞嗚В鏋愬紓甯�", e);
+            throw new RuntimeException("鑵捐鍦板浘閫嗗湴鐞嗚В鏋愬紓甯�", e);
+        }
+    }
+
+    /**
+     * 鍒ゆ柇涓や釜缁忕含搴︽槸鍚﹀湪鍚屼竴涓煄甯�
+     *
+     * @param lat1 绗竴涓偣绾害
+     * @param lng1 绗竴涓偣缁忓害
+     * @param lat2 绗簩涓偣绾害
+     * @param lng2 绗簩涓偣缁忓害
+     * @return true=鍚屽煄锛宖alse=涓嶅悓鍩�
+     */
+    public static boolean isSameCity(double lat1, double lng1, double lat2, double lng2) {
+        JSONObject result1 = reverseGeocode(lat1, lng1);
+        JSONObject result2 = reverseGeocode(lat2, lng2);
+
+        String city1 = result1.getJSONObject("ad_info").getString("city");
+        String city2 = result2.getJSONObject("ad_info").getString("city");
+
+        log.info("鍒ゆ柇鍚屽煄: ({},{}) => city={}, ({},{}) => city={}", lat1, lng1, city1, lat2, lng2, city2);
+
+        return city1 != null && city1.equals(city2);
+    }
 }

--
Gitblit v1.9.3