商品列表 返回区域信息

This commit is contained in:
2024-05-16 16:41:13 +08:00
parent 63921852e9
commit 200b75e04d
7 changed files with 38 additions and 16 deletions

View File

@@ -17,6 +17,7 @@ import static java.lang.Math.sin;
public class LocationUtils {
/**
* 通过Ip获取定位信息
*
* @param ip
* @return
*/
@@ -24,7 +25,7 @@ public class LocationUtils {
Map<String, String> param = new HashMap<>();
//超掌柜生活-用户端
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
if(StringUtils.isNotBlank(ip)){
if (StringUtils.isNotBlank(ip)) {
param.put("ip", ip);
}
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/ip", param);
@@ -36,7 +37,7 @@ public class LocationUtils {
*/
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);
String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location=" + location, String.class);
ObjectMapper objectMapper = new ObjectMapper();
// 将 JSON 字符串解析为 JsonNode 对象
try {
@@ -49,6 +50,7 @@ public class LocationUtils {
/**
* 行政区域查询
*
* @param keywords
* @return
*/
@@ -83,12 +85,21 @@ public class LocationUtils {
double a = radLat1 - radLat2;
double b = radLng1 - radLng2;
double dis= 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
double dis = 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
BigDecimal bigDecimalValue = new BigDecimal(dis);
bigDecimalValue = bigDecimalValue.setScale(3, RoundingMode.DOWN);
return bigDecimalValue;
}
public static String getDistanceString(double lng1, double lat1, double lng2, double lat2) {
BigDecimal distance = getDistanceFrom2LngLat(lng1, lat1, lng2, lat2);
if (distance.compareTo(BigDecimal.ONE) < 0) {
return distance.multiply(new BigDecimal(1000)) + "m";
} else {
return distance + "km";
}
}
/**
* @param longitude 经度 108
* @param latitude 纬度 34
@@ -128,14 +139,13 @@ public class LocationUtils {
}
/**
* 将角度转化为弧度
*/
public static double radians(double d) {
return d * Math.PI / 180.0;
}
//1KM
public static void main(String[] args) {
Map<String, double[]> stringMap = returnLLSquarePoint(108.975418, 34.280890, "5");