From d294abb765e4ed349907c92ce313689c6299ba7d Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期二, 02 十二月 2025 00:17:00 +0800
Subject: [PATCH] feat:地图都改为天地图的接口
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java | 45 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java
index 996bf70..a5c7675 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.system.service.impl;
import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.config.TiandituMapConfig;
import com.ruoyi.system.service.IMapService;
@@ -62,14 +63,9 @@
return null;
}
- // 鎻愬彇鍧愭爣
- JSONObject result = jsonObject.getJSONObject("result");
- if (result == null) {
- logger.warn("澶╁湴鍥惧湴鐞嗙紪鐮佸搷搴旀棤result: address={}", address);
- return null;
- }
+
- JSONObject location = result.getJSONObject("location");
+ JSONObject location = jsonObject.getJSONObject("location");
if (location == null) {
logger.warn("澶╁湴鍥惧湴鐞嗙紪鐮佸搷搴旀棤location: address={}", address);
return null;
@@ -91,4 +87,39 @@
return null;
}
}
+
+ /**
+ * 鐩存帴杩斿洖鍦板潃
+ * @param lng 缁忓害
+ * @param lat 绾害
+ * @return
+ */
+ @Override
+ public String reverseGeocoding(double lng, double lat) {
+ // 鏋勫缓澶╁湴鍥鹃�嗗湴鐞嗙紪鐮丄PI URL
+ String url = "http://api.tianditu.gov.cn/geocoder";
+ String params = "postStr={\"lon\":" + lng + ",\"lat\":" + lat + ",\"ver\":1}" +
+ "&type=geocode" +
+ "&tk=" + tiandituMapConfig.getTk();
+
+ logger.info("澶╁湴鍥鹃�嗗湴鐞嗙紪鐮佽姹�: lon={}, lat={}", lng, lat);
+
+ // 鍙戦�丠TTP璇锋眰
+ String response = HttpUtils.sendGet(url, params);
+
+ // "{\"msg\":\"ok\",\"location\":{\"score\":100,\"level\":\"闂ㄥ潃\",\"lon\":\"116.290158\",\"lat\":\"39.894696\",\"keyWord\":\"鍖椾含甯傛捣娣�鍖鸿幉鑺辨睜瑗胯矾28鍙穃"},\"searchVersion\":\"7.4.3V\",\"status\":\"0\"}"
+ logger.info("澶╁湴鍥鹃�嗗湴鐞嗙紪鐮佸搷搴�: {}", response);
+ com.alibaba.fastjson.JSONObject obj= com.alibaba.fastjson.JSONObject.parseObject(response);
+ if (obj.getInteger("status") !=0) {
+ logger.error("澶╁湴鍥鹃�嗗湴鐞嗙紪鐮佸け璐�: {}", response);
+ return null;
+ }
+ com.alibaba.fastjson.JSONObject location = obj.getJSONObject("result");
+ if (location == null) {
+ logger.error("澶╁湴鍥鹃�嗗湴鐞嗙紪鐮佸搷搴旀棤location: {}", response);
+ return null;
+ }
+ return location.getString("formatted_address");
+
+ }
}
--
Gitblit v1.9.1