From fe33646ee6e2d1e57f2b51812e94983a0e9efb04 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 14 十二月 2025 16:51:28 +0800
Subject: [PATCH] feat: 修复统计
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TiandituMapServiceImpl.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 46 insertions(+), 8 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..57cfe6c 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;
@@ -40,7 +41,14 @@
if (address == null || address.trim().isEmpty()) {
return null;
}
-
+ if(address.indexOf(",")>0){
+ String[] split = address.split(",");
+ address=split[0];
+ }
+ if(address.indexOf("锛�")>0){
+ String[] split = address.split("锛�");
+ address=split[0];
+ }
try {
// 鏋勫缓澶╁湴鍥惧湴鐞嗙紪鐮丄PI URL
String url = "http://api.tianditu.gov.cn/geocoder";
@@ -62,14 +70,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 +94,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