aijinhui
2023-08-31 a152548db005be9227730a3166dc233d94a52c5f
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
44
45
46
47
48
49
50
51
52
package com.ruoyi.test.Geo;
 
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.utils.gis.Point;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description:
 * @ClassName: main
 * @Author: 刘苏义
 * @Date: 2023年08月30日9:55:12
 **/
class Main {
    public static void main(String[] args) {
        GeofenceManager geofenceManager = new GeofenceManager();
 
        GeofenceCallback geofenceCallback= new GeofenceCallback() {
            @Override
            public void onEnter(String id,SysUser user) {
                System.out.println("用户" + user.getUserId() + "进入电子围栏" + id + "区域,触发报警!");
            }
 
            @Override
            public void onExit(String id,SysUser user) {
                System.out.println("用户" + user.getUserId() + "未在电子围栏" + id + "区域。");
            }
        };
 
        List<Point> polygonVertices = new ArrayList<>();
        polygonVertices.add(new Point(126.6491, 45.739108));
        polygonVertices.add(new Point(126.643458, 45.731584));
        polygonVertices.add(new Point(126.654921, 45.726979));
        polygonVertices.add(new Point(126.660742, 45.734956));
        Geofence geofence = new Geofence("1",polygonVertices, geofenceCallback);
        geofenceManager.addGeofence(geofence);
 
        List<Point> polygonVertices1 = new ArrayList<>();
        polygonVertices1.add(new Point(126.655244,45.726576));
        polygonVertices1.add(new Point(126.67242,45.720586));
        polygonVertices1.add(new Point(126.679606,45.729143));
        polygonVertices1.add(new Point(126.660993,45.734881));
        Geofence geofence1 = new Geofence("2",polygonVertices1,geofenceCallback);
        geofenceManager.addGeofence(geofence1);
 
        Point userCoordinates = new Point(126.666455,45.727986);
        SysUser user = new SysUser();
        user.setUserId("55555");
        geofenceManager.checkCoordinates(userCoordinates, user);
    }
}