Pu Zhibing
2025-03-26 7f26677ab7f9b83697370fa142dd1686cdf4082a
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
package com.ruoyi.other.util.tencentMap;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
 
/**
 * 腾讯地图
 * @author zhibing.pu
 * @Date 2024/12/19 9:37
 */
@Slf4j
public class TencentMapUtil {
 
    private static String key = "NH7BZ-XNW6Z-IKUX7-TL3H2-UN6RO-KKFHQ";
    
    /**
     * 根据经纬度获取行政区划代码
     * @param lon   经度
     * @param lat   纬度
     * @param poi   是否返回周边poi
     * @return
     */
    public static String inverseGeographicalAnalysis(String lon, String lat, boolean poi){
        HttpRequest get = HttpUtil.createGet("https://apis.map.qq.com/ws/geocoder/v1/?location=" + lat + "," + lon + "&key=" + key + "&get_poi=" + (poi ? 1 : 0));
        HttpResponse execute = get.execute();
        JSONObject jsonObject = JSON.parseObject(execute.body());
        Integer status = jsonObject.getInteger("status");
        if(0 != status){
            log.error(jsonObject.getString("message"));
            return null;
        }
        JSONObject result = jsonObject.getJSONObject("result");
        JSONObject ad_info = result.getJSONObject("ad_info");
        return ad_info.getString("adcode");
    }
}