Polygon demo
GeoJSON configuration, point classification, native geofences, and the limits of the demonstration event queue.
A flow separate from tracking
The polygon demo supports applying a JSON configuration, starting region monitoring, injecting samples, and observing entry and proximity events. It uses the configure, startMonitoring, injectTestLocation, and simulateDelivery methods of the GeoMonitoring module.
Route tracking uses a different family of Tracking methods and a separate queue. Polygons do not limit the positions sent to the API, and polygon events are not published through the route transport.
The app's current screen is Track: the initial route redirects to /tracking, and the layout does not mount GeoMonitoringProvider. The editor components and polygon facade remain in the code and tests, but are not accessible through the current navigation. Exercising them requires a development environment that integrates the facade or calls the module explicitly. The remaining provider reads native state without automatically reapplying the sample JSON.
Configuration accepted by the TypeScript facade
The configuration contains a nonempty polygons list. Each item includes identification, an enabled flag, geometry, and behavior parameters.
| Field | Purpose |
|---|---|
id and name | Zone identification |
enabled | Includes the zone in or excludes it from monitoring |
geometry | GeoJSON Polygon with a single outer ring |
proximityThresholdMeters | Maximum distance for a position to be considered nearby |
proximityIntervalSeconds | Target interval recorded in telemetry |
proximityMinDistanceDeltaMeters | Change threshold used by the TypeScript decision model |
hysteresisMeters | Margin used in the accuracy criterion on Android and in the TypeScript model |
minimumDwellSeconds | Minimum dwell time to confirm entry |
cooldownSeconds | Delay after exit before allowing a new entry |
metadata | Optional object associated with the zone |
Numeric configuration parameters must be positive. The validator requires finite coordinates in GeoJSON order, [longitude, latitude], a closed ring, and at least three distinct vertices plus a repeat of the first vertex.
The TypeScript facade rejects holes, MultiPolygon, and geometries other than Polygon. A heuristic limited to the area used during development detects swapped latitude and longitude; it does not detect every possible reversed pair worldwide.
The Android parser repeats validation and requires unique IDs. The Swift implementation decodes the model and relies on facade validation for several of these rules; validation is not fully equivalent across all native entry points.
Geometric classification
The TypeScript model uses an edge-crossing point-in-polygon test, treats the boundary as inside, and calculates the shortest distance to the outer segments. Distance is zero when the point is inside.
| Result | Criterion in the TypeScript model and Android |
|---|---|
uncertain | Accuracy worse than the proximity threshold plus the hysteresis margin |
inside | Point inside the polygon with accepted accuracy |
near | External point at a distance less than or equal to the proximity threshold |
outside | All other positions |
Distance to segments uses a local projection in meters. This is demonstration geometry for local zones; there is no special handling for antimeridian crossings or continental-scale polygons.
In the Swift polygon service, current geometric classification produces inside, near, or outside without applying Android's accuracy gate. uncertain appears when configuration or classification is unavailable. Accuracy behavior should not be assumed equivalent between the platforms.
hysteresisMeters does not implement a complete state machine to smooth boundary transitions. On Android and in the TypeScript model, its observed use is the accuracy threshold described above.
Why a native circle is used
The APIs in use register circular regions. The code calculates a circle to receive a system trigger, then checks the position against the polygon geometry.
The circle alone does not prove entry into the zone. A person can be inside the circle while remaining outside the polygon; point-in-polygon confirmation distinguishes the two.
| Platform | Registered circle |
|---|---|
| Android | Bounding-box center; radius to the farthest vertex, plus 5 meters |
| iOS | Bounding-box center; radius to the farthest vertex, plus the proximity threshold |
iOS caps the radius at maximumRegionMonitoringDistance when the system supplies that maximum. If the requested circle is larger, capping it may leave part of the geometry outside the monitored region.
On Android, the 5-meter margin does not necessarily cover the entire configured proximity band. A position classified as near may be outside the circle that produces the native trigger.
The project does not dynamically select subsets to accommodate large numbers of zones. Registration failures are reported; a configured list should not be treated as unlimited system capacity.
Native confirmation on Android
GeofencingClient registers entry and exit, with an initial entry trigger. The receiver forwards only IDs managed by the module to the service.
On entry, the service tries a last known location up to 2 minutes old. If it is unsuitable, it requests a current high-accuracy position. An unavailable position, failure, or missing permission produces an uncertain state instead of confirming entry.
After obtaining the position, the service classifies it and may create a proximity event. Entry must satisfy dwell and cooldown checks. A generation counter invalidates old confirmations after stopping or replacing the configuration.
Leaving the circle clears that zone's entry session. Configuring new polygons on Android stops previous monitoring; it must be started again.
Native confirmation on iOS
The service registers CLCircularRegion and requests its initial state. Entry or an initial inside state triggers requestLocation(); the callback confirms only polygons awaiting a location.
Leaving the region ends the entry session. Loss of authorization or a monitoring failure disables the managed regions.
When configuration is applied during active monitoring, iOS attempts to replace the regions while keeping monitoring active; if preparation fails, it stops monitoring. This differs from Android's behavior.
In current confirmations, the services use confirmation time as the sample's time reference. As a result, sampleAgeSeconds in this path should not be interpreted as a faithful measurement of the original GPS sample's age in every case.
Dwell time and new entries
Each polygon maintains a session with an active-entry flag, candidate timestamp, and last exit. The first inside classification begins the candidate period; a later confirmation must satisfy minimumDwellSeconds to generate polygon_enter.
After entry is confirmed, further inside positions do not repeatedly generate the same entry. Exit resets the session, and cooldownSeconds limits the next confirmation.
The native path can schedule another dwell confirmation. This delay runs within the process and depends on execution opportunities granted by the system; it does not promise exact background timing.
Android synthetic samples do not automatically schedule a second sample. Another inside position must be injected after enough time has passed to demonstrate dwell time.
Implemented telemetry and the helper model
telemetry.ts contains decision functions based on interval or distance change, with unit tests. These functions are not connected to the current native service.
Native services can add polygon_proximity for each sample accepted as inside or nearby. proximityIntervalSeconds appears as a target interval in records, but there is no guaranteed periodic polling at that interval or complete application of the helper model's change threshold in those services.
This distinction prevents a configurable field or a pure-function test from being interpreted as proof of integrated background behavior.
Demonstration queue
Events are persisted in SharedPreferences on Android and UserDefaults on iOS. Each record includes an ID, type, polygon, timestamp, state, attempts, and available diagnostic data.
| State | Meaning in the demo |
|---|---|
pending | Created and not yet marked by the simulation |
delivering | Simulated attempt; increments attempts when entering this state |
failed | Simulated failure |
delivered | Terminal state for simulated delivery |
superseded | Terminal state allowed only for proximity events |
simulateDelivery() does not make HTTP requests. The simulation cannot modify terminal states again, and entry events cannot be superseded like proximity events. pendingEvents counts only records literally in pending, not all undelivered records.
There is no HTTP retry, server ACK, or queue-draining policy equivalent to the real route queue. Durability guarantees also differ from that queue's SQLite transactions.
Repository sources
geo-demo/src/features/geo-monitoring/config-validation.tsgeo-demo/src/features/geo-monitoring/geometry.tsgeo-demo/src/features/geo-monitoring/telemetry.tsgeo-demo/src/features/geo-monitoring/queue-model.tsgeo-demo/src/features/geo-monitoring/geo-monitoring-store.tsgeo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/GeoMonitoringService.ktgeo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/GeoGeofenceReceiver.ktgeo-demo/modules/geo-monitoring/ios/GeoMonitoringService.swift