MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / Geofence

Class Geofence

CodenameOne/src/com/codename1/location/Geofence.java:80–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78///
79/// - GeofenceListener
80public class Geofence {
81
82 private final String id;
83
84 // Location of the geofence
85 private final Location loc;
86
87 // radius in metres.
88 private final int radius;
89
90 // Expiration in milliseconds . Duration, not timestamp. -1L to never expire.
91 private final long expiration;
92
93 /// Constructor
94 ///
95 /// #### Parameters
96 ///
97 /// - `id`: unique identifier
98 ///
99 /// - `loc`: the center location of this Geofence
100 ///
101 /// - `radius`: @param radius the radius in meters. Note that the actual radius will vary
102 /// on an actual device depending on the hardware and OS. Typical android and iOS devices
103 /// have a minimum radius of 100m.
104 ///
105 /// - `expiration`: the expiration time in milliseconds. Note that this is a duration, not a timestamp. Use -1 to never expire.
106 public Geofence(String id, Location loc, int radius, long expiration) {
107 this.id = id;
108 this.loc = loc;
109 this.radius = radius;
110 this.expiration = expiration;
111 }
112
113 /// Creates a comparator for sorting Geofences from the current Geofence.
114 public static Comparator<Geofence> createDistanceComparator(final Geofence refRegion) {
115 return new Comparator<Geofence>() {
116
117 @Override
118 public int compare(Geofence o1, Geofence o2) {
119 double d1 = refRegion.getDistanceTo(o1);
120 double d2 = refRegion.getDistanceTo(o2);
121 return d1 < d2 ? -1 : d2 < d1 ? 1 : 0;
122 }
123
124 };
125 }
126
127 /// Creates a comparator for sorting Geofences from the given reference point.
128 public static Comparator<Geofence> createDistanceComparator(final Location refPoint) {
129 return new Comparator<Geofence>() {
130
131 @Override
132 public int compare(Geofence o1, Geofence o2) {
133 double d1 = Math.max(0, refPoint.getDistanceTo(o1.getLoc()) - o1.getRadius());
134 double d2 = Math.max(0, refPoint.getDistanceTo(o2.getLoc()) - o2.getRadius());
135 return d1 < d2 ? -1 : d2 < d1 ? 1 : 0;
136 }
137

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected