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