测试环境redis 更换到0库
通用接口添加 根据经纬度获取位置信息接口
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -27,6 +31,22 @@ public class LocationUtils {
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过经纬度获取信息
|
||||
*/
|
||||
public static JsonNode geocode(String location) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location="+location, String.class);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 将 JSON 字符串解析为 JsonNode 对象
|
||||
try {
|
||||
JsonNode jsonNode = objectMapper.readTree(s).get("regeocode");
|
||||
return jsonNode;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 行政区域查询
|
||||
* @param keywords
|
||||
@@ -37,7 +57,7 @@ public class LocationUtils {
|
||||
//超掌柜生活-用户端
|
||||
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords", keywords);
|
||||
param.put("subdistrict", "2");
|
||||
param.put("subdistrict", "1");
|
||||
param.put("extensions", "base");
|
||||
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param);
|
||||
return s;
|
||||
@@ -80,7 +100,7 @@ public class LocationUtils {
|
||||
* 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
*/
|
||||
public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, String distanceInKm) {
|
||||
BigDecimal distanceKm = new BigDecimal(10);
|
||||
BigDecimal distanceKm = new BigDecimal(20);
|
||||
if (StringUtils.isNotBlank(distanceInKm)) {
|
||||
distanceKm = new BigDecimal(distanceInKm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user