无关风月
2 天以前 165e73d176191ae75b57c70e049c0cfd552bbdfa
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
41
42
43
package com.ruoyi.web.util;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
 
import java.math.BigDecimal;
import java.util.List;
 
public class MainApp {
    public static void main(String[] args) {
        double startLat = 39.9042;
        double startLon = 118.4074;
        double endLat = 39.9042;
        double endLon = 119.4074;
 
        double userLat = 39.9042;
        double userLon = 116.4074;
 
        double radius = 50; // 单位:米
        int segments = 4;   // 四段,共 5 个点
        try {
            String routeJson = AmapApiClient.getDrivingRoute(startLat, startLon, endLat, endLon);
            // 转化为json对象
            JSONObject jsonObject = JSONObject.parseObject(routeJson);
            JSONObject route = jsonObject.getJSONObject("route");
            JSONArray paths = route.getJSONArray("paths");
            JSONObject o = (JSONObject)paths.get(0);
            BigDecimal distance = o.getBigDecimal("distance");
            System.err.println( paths);
 
            List<double[]> fivePoints = PathParser.parseAndInterpolate(routeJson, segments,startLat, startLon, endLat, endLon);
 
            if (GeoChecker.isInAnyCircle(userLat, userLon, fivePoints, radius)) {
                System.out.println("✅ 成功!您位于某个圆形电子围栏范围内。");
            } else {
                System.out.println("❌ 失败!您不在任何圆形电子围栏范围内。");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}