How geolocation works
Consent-based collection, native and test positions, and the limits of background tracking.
What the system collects
Geo Tracking is a route tracking lab. The app records positions supplied by the operating system, saves each position on the device, and sends authenticated batches to the API. The dashboard displays the received history and lets users change collection parameters.
The implementation lives in the local GeoMonitoring Expo module, written in Kotlin and Swift. The React Native app handles the interface, consent, connection setup, and simulation; continuous collection and transport of real positions run in native code.
The same module contains two independent flows:
| Flow | Purpose | Persistence | Delivery |
|---|---|---|---|
| Tracking | Record and transmit a route | Native SQLite | Real HTTP with acknowledgment by ID |
| Polygons | Demonstrate classification, entry, and proximity | Native preferences | Simulated state changes |
The polygon demo does not filter the route sent to the API. Starting one flow does not automatically start the other.
From tapping Start to the dashboard
- The app configures
endpoint,deviceId, and the device credential. Configuring a connection does not authorize collection. - The user reads the background location disclosure and starts tracking through the interface.
- The flow checks location access while in use, requests background location access, and asks for notification permission on supported Android versions.
- The native module persists local authorization and activates the platform's location provider.
- Each valid position receives an
eventId, its source, and the current configuration version. - The position enters SQLite before any HTTP attempt.
- The transport sends up to 100 positions per request; only acknowledged IDs leave the queue.
- The server persists the batch and publishes new positions to dashboards connected over WebSocket.
The return value of startTracking() or syncTracking() is a snapshot of the process state. It does not mean a position has already reached the server. Subsequent counts and events show the outcome of the asynchronous operation.
Who controls collection
The system separates local authorization from remote permission to collect:
| Field or action | Meaning |
|---|---|
configured | A connection has been configured; this does not prove current connectivity |
authorized | The user started a local session that has not been stopped |
enabled | Native collection is active according to the service state |
Remote tracking.enabled | Allows or pauses collection within a locally authorized session |
| Local stop | Revokes the local session and stops collection |
A remote pause preserves local authorization. If the configuration allows collection again and the process gets an opportunity to run, the same session can continue. This is why the Stop tracking button remains available even when collection is paused remotely.
A local stop has a different effect: remote configuration does not create new authorization. Pending records remain in the queue and can synchronize after the stop; stopping collection does not erase history.
A position record
| Field | Source and interpretation |
|---|---|
eventId | UUID created on the device; remains unchanged across retries |
latitude and longitude | Finite coordinates within valid geographic bounds |
accuracyMeters | Horizontal accuracy reported by the source, from 0 to 10,000 meters |
capturedAt | Capture timestamp in ISO 8601 format |
provider | native for a system callback; test for synthetic injection |
configVersion | Configuration version known when the event was created |
receivedAt | Added by the server when persisting the event |
accuracyMeters is neither distance traveled nor error measured against an external reference. It is an estimate supplied by the provider or the test.
Capture and receipt timestamps serve different purposes. An old position can arrive after connectivity recovers; that does not make it the most recent position along the route.
Native and synthetic positions
provider:native identifies positions received through the native callback. A route applied to an emulator or simulator's GPS also follows this callback and receives this source. That result demonstrates integration with the simulated system, not a route traveled on a physical device.
injectTrackingLocation() always stores provider:test, even if the supplied object specifies another source. The sample uses the same SQLite queue and HTTP transport as tracking. This exercises persistence, retries, and the dashboard without claiming that real movement occurred.
Route simulation is controlled by the app. It can use a current system position as its starting point, but the generated steps remain synthetic. Running the route depends on the JavaScript interface's lifecycle.
The server keeps latestByProvider.native and latestByProvider.test separately. Selection uses capturedAt, with eventId as a tiebreaker; a recent synthetic sequence does not hide the latest native position.
Collection parameters
| Parameter | Initial value | Accepted range |
|---|---|---|
tracking.enabled | true | Boolean |
distanceFilterMeters | 10 meters | 0 to 1,000 meters |
intervalSeconds | 5 seconds | Integer from 1 to 300 seconds |
version | 1 | Positive integer |
On Android, distance and interval are part of a high-accuracy request to the Fused Location Provider. On iOS, distance is applied to CLLocationManager, and the interval filters callbacks before positions are persisted.
The interval is a request or a filter, depending on the platform. It does not promise exactly one sample every N seconds. GPS availability, movement, permissions, and execution time granted by the system affect the results.
The current code does not implement activity detection to switch automatically between stationary and moving modes. It also does not measure battery consumption to choose accuracy dynamically.
Offline behavior
Collection can continue saving positions while transport fails. Each service allows only one synchronization at a time, retries with increasing delays, and attempts delivery when connectivity returns.
The app exposes pendingCount, uploadedCount, lastSyncAt, and lastError. The queue does not automatically discard old records to make room for new ones. If persistence fails, collection stops or pauses with an explicit error.
A successful HTTP response without acknowledged IDs from the batch does not empty the queue. See Queue and synchronization for the complete explanation.
Background execution and resumption
On Android, a location foreground service maintains a notification and provides a stop action. The system may recreate the service while the session remains authorized, without guaranteeing resumption after every type of termination.
On iOS, CLLocationManager uses the background location capability. Synchronization takes advantage of callbacks, connectivity notifications, and execution windows. After a remote pause completely stops location updates, a suspended process does not automatically receive another execution window just because the server configuration changed.
Persisting authorization and the queue does not guarantee collection during force-stop, device reboot, or manufacturer power restrictions. The repository records simulator trials; Field testing describes evaluation on physical devices.
Where the feature is available
A native build containing the local module is required. The web implementation returns an unavailable state and rejects native tracking configuration, start, synchronization, and injection.
The web dashboard consumes the API and displays positions. It does not replace the location service in the installed app.
Repository sources
geo-demo/modules/geo-monitoring/src/GeoMonitoringModule.tsgeo-demo/modules/geo-monitoring/src/GeoMonitoringModule.web.tsgeo-demo/src/features/tracking/start-tracking.tsgeo-demo/src/features/tracking/native-tracking.tsgeo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingEngine.ktgeo-demo/modules/geo-monitoring/ios/GeoTrackingService.swifttracking-server/src/index.tsdocs/tracking-contract.mddocs/validation-2026-10-15.md