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"); } }