吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.sxkj.common.utils;
 
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.Objects;
 
/**
 * 获取地址类
 *
 * @author ruoyi
 */
public class TxAddressUtils {
    /**
     * 腾讯逆地理位置获取key
     */
    private static final String TENG_XUN_KEY = "R3YBZ-76FKU-HO6VE-4FATW-QWGVT-SIF2D";
    private static final Logger log = LoggerFactory.getLogger(TxAddressUtils.class);
 
 
    // 未知地址
    public static final String UNKNOWN = "XX XX";
 
    /**
     * 腾讯逆地理位置解析
     *
     * @param address 详细地址
     * @return
     */
    public static JSONObject getAddressLocation(String address) {
        try {
 
            String path = "https://apis.map.qq.com/ws/geocoder/v1/?address=";
            String rspStr = HttpUtils.sendGet(path, "address=" + address+"&key=" + TENG_XUN_KEY, "utf-8");
            if (StringUtils.isEmpty(rspStr)) {
                log.error("获取地理位置异常 {}", rspStr);
                return null;
            }
            JSONObject obj = JSONObject.parseObject(rspStr);
            Integer status = obj.getInteger("status");
            if (0 == status) {
                JSONObject result = obj.getJSONObject("result");
                if (Objects.nonNull(result)) {
                    JSONObject jsonObject = result.getJSONObject("location");
                    return jsonObject;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
 
 
}