react-native-nitro-location-tracking 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -87
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/GeofenceManager.kt +10 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/LocationEngine.kt +3 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt +13 -0
- package/ios/GeofenceManager.swift +6 -0
- package/ios/LocationEngine.swift +5 -0
- package/ios/NitroLocationTracking.swift +12 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts +2 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.cpp +10 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.hpp +2 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/HybridNitroLocationTrackingSpec.kt +8 -0
- package/nitrogen/generated/ios/c++/HybridNitroLocationTrackingSpecSwift.hpp +16 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec_cxx.swift +24 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.hpp +2 -0
- package/package.json +1 -1
- package/src/NitroLocationTracking.nitro.ts +9 -0
package/README.md
CHANGED
|
@@ -91,7 +91,8 @@ const granted = await requestLocationPermission(
|
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
title: 'Background Location',
|
|
94
|
-
message:
|
|
94
|
+
message:
|
|
95
|
+
'Allow background location to keep tracking while the app is minimized.',
|
|
95
96
|
buttonPositive: 'Allow',
|
|
96
97
|
buttonNegative: 'Deny',
|
|
97
98
|
}
|
|
@@ -109,13 +110,13 @@ import { useDriverLocation } from 'react-native-nitro-location-tracking';
|
|
|
109
110
|
import type { LocationConfig } from 'react-native-nitro-location-tracking';
|
|
110
111
|
|
|
111
112
|
const config: LocationConfig = {
|
|
112
|
-
desiredAccuracy: 'high',
|
|
113
|
-
distanceFilter: 10,
|
|
114
|
-
intervalMs: 3000,
|
|
115
|
-
fastestIntervalMs: 1000,
|
|
116
|
-
stopTimeout: 5,
|
|
117
|
-
stopOnTerminate: false,
|
|
118
|
-
startOnBoot: true,
|
|
113
|
+
desiredAccuracy: 'high', // 'high' | 'balanced' | 'low'
|
|
114
|
+
distanceFilter: 10, // meters
|
|
115
|
+
intervalMs: 3000, // Android only
|
|
116
|
+
fastestIntervalMs: 1000, // Android only
|
|
117
|
+
stopTimeout: 5, // minutes before declaring stopped
|
|
118
|
+
stopOnTerminate: false, // keep tracking after app close (Android)
|
|
119
|
+
startOnBoot: true, // restart tracking after reboot (Android)
|
|
119
120
|
foregroundNotificationTitle: 'Tracking Active',
|
|
120
121
|
foregroundNotificationText: 'Your location is being tracked',
|
|
121
122
|
};
|
|
@@ -155,8 +156,8 @@ const connectionConfig: ConnectionConfig = {
|
|
|
155
156
|
authToken: 'your-auth-token',
|
|
156
157
|
reconnectIntervalMs: 5000,
|
|
157
158
|
maxReconnectAttempts: 10,
|
|
158
|
-
batchSize: 5,
|
|
159
|
-
syncIntervalMs: 10000,
|
|
159
|
+
batchSize: 5, // locations per batch upload
|
|
160
|
+
syncIntervalMs: 10000, // flush queue every 10s
|
|
160
161
|
};
|
|
161
162
|
|
|
162
163
|
function RideScreen() {
|
|
@@ -238,10 +239,10 @@ NitroLocationModule.onLocation((location) => {
|
|
|
238
239
|
|
|
239
240
|
**Platform behavior:**
|
|
240
241
|
|
|
241
|
-
| Platform | Per-location detection
|
|
242
|
-
|
|
243
|
-
| Android
|
|
244
|
-
| iOS
|
|
242
|
+
| Platform | Per-location detection | Device-level detection |
|
|
243
|
+
| -------- | -------------------------------------------------------------- | ----------------------------------- |
|
|
244
|
+
| Android | `Location.isMock` (API 31+) / `isFromMockProvider` (API 18+) | `AppOpsManager` mock location check |
|
|
245
|
+
| iOS | `CLLocation.sourceInformation.isSimulatedBySoftware` (iOS 15+) | Simulator detection |
|
|
245
246
|
|
|
246
247
|
### Smooth Map Marker Animation
|
|
247
248
|
|
|
@@ -287,7 +288,10 @@ function MapScreen() {
|
|
|
287
288
|
Calculate bearing between two coordinates and handle rotation smoothing:
|
|
288
289
|
|
|
289
290
|
```tsx
|
|
290
|
-
import {
|
|
291
|
+
import {
|
|
292
|
+
calculateBearing,
|
|
293
|
+
shortestRotation,
|
|
294
|
+
} from 'react-native-nitro-location-tracking';
|
|
291
295
|
|
|
292
296
|
// Calculate bearing from point A to point B (in degrees, 0-360)
|
|
293
297
|
const bearing = calculateBearing(
|
|
@@ -333,6 +337,49 @@ NitroLocationModule.removeAllGeofences();
|
|
|
333
337
|
|
|
334
338
|
> **Note:** iOS limits geofence regions to 20 per app. Android supports up to 100.
|
|
335
339
|
|
|
340
|
+
### Distance Utilities
|
|
341
|
+
|
|
342
|
+
Calculate distance between two points or from the current location to a registered geofence:
|
|
343
|
+
|
|
344
|
+
```tsx
|
|
345
|
+
import NitroLocationModule from 'react-native-nitro-location-tracking';
|
|
346
|
+
|
|
347
|
+
// Calculate distance between any two coordinates (returns meters)
|
|
348
|
+
const meters = NitroLocationModule.getDistanceBetween(
|
|
349
|
+
41.311158,
|
|
350
|
+
69.279737, // point A
|
|
351
|
+
41.3152,
|
|
352
|
+
69.2851 // point B
|
|
353
|
+
);
|
|
354
|
+
console.log(`Distance: ${meters.toFixed(0)}m`);
|
|
355
|
+
|
|
356
|
+
// Get distance from current location to a registered geofence center
|
|
357
|
+
// First, register a geofence
|
|
358
|
+
NitroLocationModule.addGeofence({
|
|
359
|
+
id: 'branch-123',
|
|
360
|
+
latitude: 41.311158,
|
|
361
|
+
longitude: 69.279737,
|
|
362
|
+
radius: 150,
|
|
363
|
+
notifyOnEntry: true,
|
|
364
|
+
notifyOnExit: true,
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Then query distance using the same region id
|
|
368
|
+
const distToBranch = NitroLocationModule.getDistanceToGeofence('branch-123');
|
|
369
|
+
if (distToBranch >= 0) {
|
|
370
|
+
console.log(`Distance to branch: ${distToBranch.toFixed(0)}m`);
|
|
371
|
+
} else {
|
|
372
|
+
console.warn('Geofence not found or no location available');
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Key points:**
|
|
377
|
+
|
|
378
|
+
- Both methods use **native distance APIs** (`CLLocation.distance(from:)` on iOS, `Location.distanceBetween()` on Android) — no JS-thread computation.
|
|
379
|
+
- `getDistanceBetween()` is a pure utility — pass any two lat/lng pairs.
|
|
380
|
+
- `getDistanceToGeofence()` uses the device's **last known native location** and the registered geofence center. Returns `-1` if the region ID is not found or no location is available.
|
|
381
|
+
- The `regionId` is the `id` string you set when calling `addGeofence()`.
|
|
382
|
+
|
|
336
383
|
### Speed Monitoring
|
|
337
384
|
|
|
338
385
|
Get alerts when speed crosses configurable thresholds:
|
|
@@ -342,9 +389,9 @@ import NitroLocationModule from 'react-native-nitro-location-tracking';
|
|
|
342
389
|
|
|
343
390
|
// Configure speed thresholds
|
|
344
391
|
NitroLocationModule.configureSpeedMonitor({
|
|
345
|
-
maxSpeedKmh: 120,
|
|
346
|
-
minSpeedKmh: 5,
|
|
347
|
-
checkIntervalMs: 0,
|
|
392
|
+
maxSpeedKmh: 120, // alert when exceeding 120 km/h
|
|
393
|
+
minSpeedKmh: 5, // alert when below 5 km/h (idle detection)
|
|
394
|
+
checkIntervalMs: 0, // check on every location update
|
|
348
395
|
});
|
|
349
396
|
|
|
350
397
|
// Listen for speed state transitions
|
|
@@ -434,13 +481,55 @@ switch (status) {
|
|
|
434
481
|
}
|
|
435
482
|
```
|
|
436
483
|
|
|
437
|
-
| Status
|
|
438
|
-
|
|
439
|
-
| `notDetermined` | Not yet asked
|
|
440
|
-
| `denied`
|
|
441
|
-
| `restricted`
|
|
442
|
-
| `whenInUse`
|
|
443
|
-
| `always`
|
|
484
|
+
| Status | iOS | Android |
|
|
485
|
+
| --------------- | ------------------------ | ---------------------------- |
|
|
486
|
+
| `notDetermined` | Not yet asked | N/A (returns `denied`) |
|
|
487
|
+
| `denied` | User denied | Fine location not granted |
|
|
488
|
+
| `restricted` | Parental/MDM restriction | N/A (returns `denied`) |
|
|
489
|
+
| `whenInUse` | Authorized when in use | Fine granted, background not |
|
|
490
|
+
| `always` | Authorized always | Fine + background granted |
|
|
491
|
+
|
|
492
|
+
### Request Permission (Native)
|
|
493
|
+
|
|
494
|
+
Request location permission directly via the native module and get the resulting status:
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
import NitroLocationModule from 'react-native-nitro-location-tracking';
|
|
498
|
+
|
|
499
|
+
async function setup() {
|
|
500
|
+
// Check current status first (no dialog)
|
|
501
|
+
const current = NitroLocationModule.getLocationPermissionStatus();
|
|
502
|
+
|
|
503
|
+
if (current === 'always' || current === 'whenInUse') {
|
|
504
|
+
// Already granted — start tracking
|
|
505
|
+
NitroLocationModule.startTracking();
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Request permission — shows the system dialog
|
|
510
|
+
const status = await NitroLocationModule.requestLocationPermission();
|
|
511
|
+
|
|
512
|
+
switch (status) {
|
|
513
|
+
case 'always':
|
|
514
|
+
case 'whenInUse':
|
|
515
|
+
NitroLocationModule.startTracking();
|
|
516
|
+
break;
|
|
517
|
+
case 'denied':
|
|
518
|
+
Alert.alert('Location Required', 'Please enable location in Settings');
|
|
519
|
+
break;
|
|
520
|
+
case 'restricted':
|
|
521
|
+
// Parental controls / MDM — cannot request
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
**Platform behavior:**
|
|
528
|
+
|
|
529
|
+
| Platform | Behavior |
|
|
530
|
+
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
531
|
+
| iOS | Calls `requestAlwaysAuthorization()`. If permission is already determined, resolves immediately with current status. If `start()` was called before permission was granted, tracking auto-starts once the user allows. |
|
|
532
|
+
| Android | Uses React Native's `PermissionAwareActivity` to show the system permission dialog for `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION`. Resolves with the resulting status after the user responds. |
|
|
444
533
|
|
|
445
534
|
## API Reference
|
|
446
535
|
|
|
@@ -453,11 +542,11 @@ interface LocationData {
|
|
|
453
542
|
latitude: number;
|
|
454
543
|
longitude: number;
|
|
455
544
|
altitude: number;
|
|
456
|
-
speed: number;
|
|
457
|
-
bearing: number;
|
|
458
|
-
accuracy: number;
|
|
459
|
-
timestamp: number;
|
|
460
|
-
isMockLocation?: boolean;
|
|
545
|
+
speed: number; // m/s
|
|
546
|
+
bearing: number; // degrees
|
|
547
|
+
accuracy: number; // meters
|
|
548
|
+
timestamp: number; // unix ms
|
|
549
|
+
isMockLocation?: boolean; // true when from a mock provider
|
|
461
550
|
}
|
|
462
551
|
```
|
|
463
552
|
|
|
@@ -466,12 +555,12 @@ interface LocationData {
|
|
|
466
555
|
```ts
|
|
467
556
|
interface LocationConfig {
|
|
468
557
|
desiredAccuracy: 'high' | 'balanced' | 'low';
|
|
469
|
-
distanceFilter: number;
|
|
470
|
-
intervalMs: number;
|
|
471
|
-
fastestIntervalMs: number;
|
|
472
|
-
stopTimeout: number;
|
|
473
|
-
stopOnTerminate: boolean;
|
|
474
|
-
startOnBoot: boolean;
|
|
558
|
+
distanceFilter: number; // meters
|
|
559
|
+
intervalMs: number; // Android only
|
|
560
|
+
fastestIntervalMs: number; // Android only
|
|
561
|
+
stopTimeout: number; // minutes before declaring stopped
|
|
562
|
+
stopOnTerminate: boolean; // keep tracking after app close (Android)
|
|
563
|
+
startOnBoot: boolean; // restart tracking after reboot (Android)
|
|
475
564
|
foregroundNotificationTitle: string;
|
|
476
565
|
foregroundNotificationText: string;
|
|
477
566
|
}
|
|
@@ -486,7 +575,7 @@ interface ConnectionConfig {
|
|
|
486
575
|
authToken: string;
|
|
487
576
|
reconnectIntervalMs: number;
|
|
488
577
|
maxReconnectAttempts: number;
|
|
489
|
-
batchSize: number;
|
|
578
|
+
batchSize: number; // locations per batch upload
|
|
490
579
|
syncIntervalMs: number; // how often to flush queue
|
|
491
580
|
}
|
|
492
581
|
```
|
|
@@ -498,7 +587,7 @@ interface GeofenceRegion {
|
|
|
498
587
|
id: string;
|
|
499
588
|
latitude: number;
|
|
500
589
|
longitude: number;
|
|
501
|
-
radius: number;
|
|
590
|
+
radius: number; // meters
|
|
502
591
|
notifyOnEntry: boolean;
|
|
503
592
|
notifyOnExit: boolean;
|
|
504
593
|
}
|
|
@@ -508,9 +597,9 @@ interface GeofenceRegion {
|
|
|
508
597
|
|
|
509
598
|
```ts
|
|
510
599
|
interface SpeedConfig {
|
|
511
|
-
maxSpeedKmh: number;
|
|
512
|
-
minSpeedKmh: number;
|
|
513
|
-
checkIntervalMs: number;
|
|
600
|
+
maxSpeedKmh: number; // speed limit in km/h
|
|
601
|
+
minSpeedKmh: number; // minimum speed threshold
|
|
602
|
+
checkIntervalMs: number; // how often to evaluate
|
|
514
603
|
}
|
|
515
604
|
```
|
|
516
605
|
|
|
@@ -539,58 +628,61 @@ type PermissionStatus =
|
|
|
539
628
|
|
|
540
629
|
### Hooks
|
|
541
630
|
|
|
542
|
-
| Hook
|
|
543
|
-
|
|
544
|
-
| `useDriverLocation(config)` | `{ location, isMoving, isTracking, startTracking, stopTracking }` | Manages location tracking lifecycle
|
|
545
|
-
| `useRideConnection(config)` | `{ connectionState, lastMessage, connect, disconnect, send }`
|
|
631
|
+
| Hook | Returns | Description |
|
|
632
|
+
| --------------------------- | ----------------------------------------------------------------- | -------------------------------------- |
|
|
633
|
+
| `useDriverLocation(config)` | `{ location, isMoving, isTracking, startTracking, stopTracking }` | Manages location tracking lifecycle |
|
|
634
|
+
| `useRideConnection(config)` | `{ connectionState, lastMessage, connect, disconnect, send }` | Manages WebSocket connection lifecycle |
|
|
546
635
|
|
|
547
636
|
### Native Module Methods
|
|
548
637
|
|
|
549
|
-
| Method
|
|
550
|
-
|
|
551
|
-
| `configure(config)`
|
|
552
|
-
| `startTracking()`
|
|
553
|
-
| `stopTracking()`
|
|
554
|
-
| `getCurrentLocation()`
|
|
555
|
-
| `isTracking()`
|
|
556
|
-
| `onLocation(callback)`
|
|
557
|
-
| `onMotionChange(callback)`
|
|
558
|
-
| `configureConnection(config)`
|
|
559
|
-
| `connectWebSocket()`
|
|
560
|
-
| `disconnectWebSocket()`
|
|
561
|
-
| `sendMessage(message)`
|
|
562
|
-
| `getConnectionState()`
|
|
563
|
-
| `onConnectionStateChange(callback)`
|
|
564
|
-
| `onMessage(callback)`
|
|
565
|
-
| `forceSync()`
|
|
566
|
-
| `isFakeGpsEnabled()`
|
|
567
|
-
| `setRejectMockLocations(reject)`
|
|
568
|
-
| `addGeofence(region)`
|
|
569
|
-
| `removeGeofence(regionId)`
|
|
570
|
-
| `removeAllGeofences()`
|
|
571
|
-
| `onGeofenceEvent(callback)`
|
|
572
|
-
| `
|
|
573
|
-
| `
|
|
574
|
-
| `
|
|
575
|
-
| `
|
|
576
|
-
| `
|
|
577
|
-
| `
|
|
578
|
-
| `
|
|
579
|
-
| `
|
|
580
|
-
| `
|
|
581
|
-
| `
|
|
582
|
-
| `
|
|
583
|
-
| `
|
|
584
|
-
| `
|
|
638
|
+
| Method | Returns | Description |
|
|
639
|
+
| -------------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------------- |
|
|
640
|
+
| `configure(config)` | `void` | Set location tracking configuration |
|
|
641
|
+
| `startTracking()` | `void` | Start location tracking |
|
|
642
|
+
| `stopTracking()` | `void` | Stop location tracking |
|
|
643
|
+
| `getCurrentLocation()` | `Promise<LocationData>` | Get a one-shot location |
|
|
644
|
+
| `isTracking()` | `boolean` | Check if tracking is active |
|
|
645
|
+
| `onLocation(callback)` | `void` | Register location update callback |
|
|
646
|
+
| `onMotionChange(callback)` | `void` | Register motion state callback |
|
|
647
|
+
| `configureConnection(config)` | `void` | Set WebSocket/REST configuration |
|
|
648
|
+
| `connectWebSocket()` | `void` | Open WebSocket connection |
|
|
649
|
+
| `disconnectWebSocket()` | `void` | Close WebSocket connection |
|
|
650
|
+
| `sendMessage(message)` | `void` | Send a message via WebSocket |
|
|
651
|
+
| `getConnectionState()` | `ConnectionState` | Get current connection state |
|
|
652
|
+
| `onConnectionStateChange(callback)` | `void` | Register connection state callback |
|
|
653
|
+
| `onMessage(callback)` | `void` | Register incoming message callback |
|
|
654
|
+
| `forceSync()` | `Promise<boolean>` | Flush queued locations to server |
|
|
655
|
+
| `isFakeGpsEnabled()` | `boolean` | Check if device-level mock location is enabled |
|
|
656
|
+
| `setRejectMockLocations(reject)` | `void` | Auto-reject mock locations when `true` |
|
|
657
|
+
| `addGeofence(region)` | `void` | Start monitoring a circular geofence region |
|
|
658
|
+
| `removeGeofence(regionId)` | `void` | Stop monitoring a specific geofence |
|
|
659
|
+
| `removeAllGeofences()` | `void` | Remove all active geofences |
|
|
660
|
+
| `onGeofenceEvent(callback)` | `void` | Register geofence enter/exit callback |
|
|
661
|
+
| `getDistanceBetween(lat1, lon1, lat2, lon2)` | `number` | Calculate distance between two points in meters (native Haversine) |
|
|
662
|
+
| `getDistanceToGeofence(regionId)` | `number` | Get distance in meters from last known location to a geofence center (`-1` if not found) |
|
|
663
|
+
| `configureSpeedMonitor(config)` | `void` | Set speed monitoring thresholds |
|
|
664
|
+
| `onSpeedAlert(callback)` | `void` | Register speed state-transition callback |
|
|
665
|
+
| `getCurrentSpeed()` | `number` | Get current speed in km/h |
|
|
666
|
+
| `startTripCalculation()` | `void` | Start recording trip distance/stats |
|
|
667
|
+
| `stopTripCalculation()` | `TripStats` | Stop recording and get final stats |
|
|
668
|
+
| `getTripStats()` | `TripStats` | Get current trip stats without stopping |
|
|
669
|
+
| `resetTripCalculation()` | `void` | Reset trip calculator |
|
|
670
|
+
| `isLocationServicesEnabled()` | `boolean` | Check if GPS/location is enabled on device |
|
|
671
|
+
| `onProviderStatusChange(callback)` | `void` | Register GPS/network provider status callback |
|
|
672
|
+
| `getLocationPermissionStatus()` | `PermissionStatus` | Check current location permission without prompting |
|
|
673
|
+
| `requestLocationPermission()` | `Promise<PermissionStatus>` | Request location permission and return the resulting status |
|
|
674
|
+
| `showLocalNotification(title, body)` | `void` | Show a local notification |
|
|
675
|
+
| `updateForegroundNotification(title, body)` | `void` | Update the foreground service notification |
|
|
676
|
+
| `destroy()` | `void` | Stop tracking and disconnect |
|
|
585
677
|
|
|
586
678
|
### Utility Exports
|
|
587
679
|
|
|
588
|
-
| Export
|
|
589
|
-
|
|
590
|
-
| `LocationSmoother`
|
|
591
|
-
| `calculateBearing(from, to)`
|
|
592
|
-
| `shortestRotation(from, to)`
|
|
593
|
-
| `requestLocationPermission()` | Request location + notification permissions (Android)
|
|
680
|
+
| Export | Description |
|
|
681
|
+
| ----------------------------- | ---------------------------------------------------------- |
|
|
682
|
+
| `LocationSmoother` | Class for smooth map marker animation between updates |
|
|
683
|
+
| `calculateBearing(from, to)` | Calculate bearing between two coordinates (degrees, 0-360) |
|
|
684
|
+
| `shortestRotation(from, to)` | Calculate shortest rotation path to avoid spinning |
|
|
685
|
+
| `requestLocationPermission()` | Request location + notification permissions (Android) |
|
|
594
686
|
|
|
595
687
|
## Publishing to npm
|
|
596
688
|
|
|
@@ -135,6 +135,16 @@ class GeofenceManager(private val context: Context) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
fun distanceTo(regionId: String, lastLocation: android.location.Location?): Double {
|
|
139
|
+
val region = activeRegions[regionId] ?: return -1.0
|
|
140
|
+
val loc = lastLocation ?: return -1.0
|
|
141
|
+
val results = FloatArray(1)
|
|
142
|
+
android.location.Location.distanceBetween(
|
|
143
|
+
loc.latitude, loc.longitude, region.latitude, region.longitude, results
|
|
144
|
+
)
|
|
145
|
+
return results[0].toDouble()
|
|
146
|
+
}
|
|
147
|
+
|
|
138
148
|
fun destroy() {
|
|
139
149
|
removeAllGeofences()
|
|
140
150
|
receiver?.let {
|
|
@@ -28,6 +28,8 @@ class LocationEngine(private val context: Context) {
|
|
|
28
28
|
val tripCalculator = TripCalculator()
|
|
29
29
|
private var lastSpeed = 0f
|
|
30
30
|
private var tracking = false
|
|
31
|
+
var lastLocation: Location? = null
|
|
32
|
+
private set
|
|
31
33
|
|
|
32
34
|
val isTracking: Boolean get() = tracking
|
|
33
35
|
|
|
@@ -90,6 +92,7 @@ class LocationEngine(private val context: Context) {
|
|
|
90
92
|
// }
|
|
91
93
|
|
|
92
94
|
private fun processLocation(location: Location) {
|
|
95
|
+
lastLocation = location
|
|
93
96
|
val data = locationToData(location)
|
|
94
97
|
|
|
95
98
|
// Skip mock locations if rejection is enabled
|
package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt
CHANGED
|
@@ -346,6 +346,19 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
+
// === Distance Utilities ===
|
|
350
|
+
|
|
351
|
+
override fun getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
|
|
352
|
+
val results = FloatArray(1)
|
|
353
|
+
android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, results)
|
|
354
|
+
return results[0].toDouble()
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
override fun getDistanceToGeofence(regionId: String): Double {
|
|
358
|
+
ensureInitialized()
|
|
359
|
+
return geofenceManager?.distanceTo(regionId, locationEngine?.lastLocation) ?: -1.0
|
|
360
|
+
}
|
|
361
|
+
|
|
349
362
|
// === Notifications ===
|
|
350
363
|
|
|
351
364
|
override fun showLocalNotification(title: String, body: String) {
|
|
@@ -62,6 +62,12 @@ class GeofenceManager: NSObject, CLLocationManagerDelegate {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
func distanceTo(regionId: String, from location: CLLocation?) -> Double {
|
|
66
|
+
guard let region = activeRegions[regionId], let location = location else { return -1 }
|
|
67
|
+
let center = CLLocation(latitude: region.latitude, longitude: region.longitude)
|
|
68
|
+
return location.distance(from: center)
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
func destroy() {
|
|
66
72
|
removeAllGeofences()
|
|
67
73
|
callback = nil
|
package/ios/LocationEngine.swift
CHANGED
|
@@ -23,6 +23,11 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
23
23
|
let tripCalculator = TripCalculator()
|
|
24
24
|
var providerStatusCallback: ((LocationProviderStatus, LocationProviderStatus) -> Void)?
|
|
25
25
|
|
|
26
|
+
/// The most recently received location from Core Location (for distance calculations)
|
|
27
|
+
var lastCLLocation: CLLocation? {
|
|
28
|
+
return locationManager.location
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
override init() {
|
|
27
32
|
super.init()
|
|
28
33
|
locationManager.delegate = self
|
|
@@ -236,6 +236,18 @@ class NitroLocationTracking: HybridNitroLocationTrackingSpec {
|
|
|
236
236
|
return promise
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
// MARK: - Distance Utilities
|
|
240
|
+
|
|
241
|
+
func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) throws -> Double {
|
|
242
|
+
let loc1 = CLLocation(latitude: lat1, longitude: lon1)
|
|
243
|
+
let loc2 = CLLocation(latitude: lat2, longitude: lon2)
|
|
244
|
+
return loc1.distance(from: loc2)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
func getDistanceToGeofence(regionId: String) throws -> Double {
|
|
248
|
+
return geofenceManager.distanceTo(regionId: regionId, from: locationEngine.lastCLLocation)
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
// MARK: - Notifications
|
|
240
252
|
|
|
241
253
|
func showLocalNotification(title: String, body: String) throws {
|
|
@@ -97,6 +97,8 @@ export interface NitroLocationTracking extends HybridObject<{
|
|
|
97
97
|
onProviderStatusChange(callback: ProviderStatusCallback): void;
|
|
98
98
|
getLocationPermissionStatus(): PermissionStatus;
|
|
99
99
|
requestLocationPermission(): Promise<PermissionStatus>;
|
|
100
|
+
getDistanceBetween(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
101
|
+
getDistanceToGeofence(regionId: string): number;
|
|
100
102
|
showLocalNotification(title: string, body: string): void;
|
|
101
103
|
updateForegroundNotification(title: string, body: string): void;
|
|
102
104
|
destroy(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroLocationTracking.nitro.d.ts","sourceRoot":"","sources":["../../../src/NitroLocationTracking.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI/D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AACxD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;AAI5E,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,aAAa,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,2BAA2B,EAAE,MAAM,CAAC;IACpC,0BAA0B,EAAE,MAAM,CAAC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CAAC;IAGvD,kBAAkB,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,MAAM,CAAC;IACV,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAGhD,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzD,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAGhE,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -281,6 +281,16 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
281
281
|
return __promise;
|
|
282
282
|
}();
|
|
283
283
|
}
|
|
284
|
+
double JHybridNitroLocationTrackingSpec::getDistanceBetween(double lat1, double lon1, double lat2, double lon2) {
|
|
285
|
+
static const auto method = javaClassStatic()->getMethod<double(double /* lat1 */, double /* lon1 */, double /* lat2 */, double /* lon2 */)>("getDistanceBetween");
|
|
286
|
+
auto __result = method(_javaPart, lat1, lon1, lat2, lon2);
|
|
287
|
+
return __result;
|
|
288
|
+
}
|
|
289
|
+
double JHybridNitroLocationTrackingSpec::getDistanceToGeofence(const std::string& regionId) {
|
|
290
|
+
static const auto method = javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* regionId */)>("getDistanceToGeofence");
|
|
291
|
+
auto __result = method(_javaPart, jni::make_jstring(regionId));
|
|
292
|
+
return __result;
|
|
293
|
+
}
|
|
284
294
|
void JHybridNitroLocationTrackingSpec::showLocalNotification(const std::string& title, const std::string& body) {
|
|
285
295
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* title */, jni::alias_ref<jni::JString> /* body */)>("showLocalNotification");
|
|
286
296
|
method(_javaPart, jni::make_jstring(title), jni::make_jstring(body));
|
|
@@ -87,6 +87,8 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
87
87
|
void onProviderStatusChange(const std::function<void(LocationProviderStatus /* gps */, LocationProviderStatus /* network */)>& callback) override;
|
|
88
88
|
PermissionStatus getLocationPermissionStatus() override;
|
|
89
89
|
std::shared_ptr<Promise<PermissionStatus>> requestLocationPermission() override;
|
|
90
|
+
double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) override;
|
|
91
|
+
double getDistanceToGeofence(const std::string& regionId) override;
|
|
90
92
|
void showLocalNotification(const std::string& title, const std::string& body) override;
|
|
91
93
|
void updateForegroundNotification(const std::string& title, const std::string& body) override;
|
|
92
94
|
void destroy() override;
|
|
@@ -209,6 +209,14 @@ abstract class HybridNitroLocationTrackingSpec: HybridObject() {
|
|
|
209
209
|
@Keep
|
|
210
210
|
abstract fun requestLocationPermission(): Promise<PermissionStatus>
|
|
211
211
|
|
|
212
|
+
@DoNotStrip
|
|
213
|
+
@Keep
|
|
214
|
+
abstract fun getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double
|
|
215
|
+
|
|
216
|
+
@DoNotStrip
|
|
217
|
+
@Keep
|
|
218
|
+
abstract fun getDistanceToGeofence(regionId: String): Double
|
|
219
|
+
|
|
212
220
|
@DoNotStrip
|
|
213
221
|
@Keep
|
|
214
222
|
abstract fun showLocalNotification(title: String, body: String): Unit
|
|
@@ -318,6 +318,22 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
318
318
|
auto __value = std::move(__result.value());
|
|
319
319
|
return __value;
|
|
320
320
|
}
|
|
321
|
+
inline double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) override {
|
|
322
|
+
auto __result = _swiftPart.getDistanceBetween(std::forward<decltype(lat1)>(lat1), std::forward<decltype(lon1)>(lon1), std::forward<decltype(lat2)>(lat2), std::forward<decltype(lon2)>(lon2));
|
|
323
|
+
if (__result.hasError()) [[unlikely]] {
|
|
324
|
+
std::rethrow_exception(__result.error());
|
|
325
|
+
}
|
|
326
|
+
auto __value = std::move(__result.value());
|
|
327
|
+
return __value;
|
|
328
|
+
}
|
|
329
|
+
inline double getDistanceToGeofence(const std::string& regionId) override {
|
|
330
|
+
auto __result = _swiftPart.getDistanceToGeofence(regionId);
|
|
331
|
+
if (__result.hasError()) [[unlikely]] {
|
|
332
|
+
std::rethrow_exception(__result.error());
|
|
333
|
+
}
|
|
334
|
+
auto __value = std::move(__result.value());
|
|
335
|
+
return __value;
|
|
336
|
+
}
|
|
321
337
|
inline void showLocalNotification(const std::string& title, const std::string& body) override {
|
|
322
338
|
auto __result = _swiftPart.showLocalNotification(title, body);
|
|
323
339
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -45,6 +45,8 @@ public protocol HybridNitroLocationTrackingSpec_protocol: HybridObject {
|
|
|
45
45
|
func onProviderStatusChange(callback: @escaping (_ gps: LocationProviderStatus, _ network: LocationProviderStatus) -> Void) throws -> Void
|
|
46
46
|
func getLocationPermissionStatus() throws -> PermissionStatus
|
|
47
47
|
func requestLocationPermission() throws -> Promise<PermissionStatus>
|
|
48
|
+
func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) throws -> Double
|
|
49
|
+
func getDistanceToGeofence(regionId: String) throws -> Double
|
|
48
50
|
func showLocalNotification(title: String, body: String) throws -> Void
|
|
49
51
|
func updateForegroundNotification(title: String, body: String) throws -> Void
|
|
50
52
|
func destroy() throws -> Void
|
|
@@ -543,6 +543,30 @@ open class HybridNitroLocationTrackingSpec_cxx {
|
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
@inline(__always)
|
|
547
|
+
public final func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> bridge.Result_double_ {
|
|
548
|
+
do {
|
|
549
|
+
let __result = try self.__implementation.getDistanceBetween(lat1: lat1, lon1: lon1, lat2: lat2, lon2: lon2)
|
|
550
|
+
let __resultCpp = __result
|
|
551
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
552
|
+
} catch (let __error) {
|
|
553
|
+
let __exceptionPtr = __error.toCpp()
|
|
554
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
@inline(__always)
|
|
559
|
+
public final func getDistanceToGeofence(regionId: std.string) -> bridge.Result_double_ {
|
|
560
|
+
do {
|
|
561
|
+
let __result = try self.__implementation.getDistanceToGeofence(regionId: String(regionId))
|
|
562
|
+
let __resultCpp = __result
|
|
563
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
564
|
+
} catch (let __error) {
|
|
565
|
+
let __exceptionPtr = __error.toCpp()
|
|
566
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
546
570
|
@inline(__always)
|
|
547
571
|
public final func showLocalNotification(title: std.string, body: std.string) -> bridge.Result_void_ {
|
|
548
572
|
do {
|
|
@@ -46,6 +46,8 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
46
46
|
prototype.registerHybridMethod("onProviderStatusChange", &HybridNitroLocationTrackingSpec::onProviderStatusChange);
|
|
47
47
|
prototype.registerHybridMethod("getLocationPermissionStatus", &HybridNitroLocationTrackingSpec::getLocationPermissionStatus);
|
|
48
48
|
prototype.registerHybridMethod("requestLocationPermission", &HybridNitroLocationTrackingSpec::requestLocationPermission);
|
|
49
|
+
prototype.registerHybridMethod("getDistanceBetween", &HybridNitroLocationTrackingSpec::getDistanceBetween);
|
|
50
|
+
prototype.registerHybridMethod("getDistanceToGeofence", &HybridNitroLocationTrackingSpec::getDistanceToGeofence);
|
|
49
51
|
prototype.registerHybridMethod("showLocalNotification", &HybridNitroLocationTrackingSpec::showLocalNotification);
|
|
50
52
|
prototype.registerHybridMethod("updateForegroundNotification", &HybridNitroLocationTrackingSpec::updateForegroundNotification);
|
|
51
53
|
prototype.registerHybridMethod("destroy", &HybridNitroLocationTrackingSpec::destroy);
|
|
@@ -114,6 +114,8 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
114
114
|
virtual void onProviderStatusChange(const std::function<void(LocationProviderStatus /* gps */, LocationProviderStatus /* network */)>& callback) = 0;
|
|
115
115
|
virtual PermissionStatus getLocationPermissionStatus() = 0;
|
|
116
116
|
virtual std::shared_ptr<Promise<PermissionStatus>> requestLocationPermission() = 0;
|
|
117
|
+
virtual double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) = 0;
|
|
118
|
+
virtual double getDistanceToGeofence(const std::string& regionId) = 0;
|
|
117
119
|
virtual void showLocalNotification(const std::string& title, const std::string& body) = 0;
|
|
118
120
|
virtual void updateForegroundNotification(const std::string& title, const std::string& body) = 0;
|
|
119
121
|
virtual void destroy() = 0;
|
package/package.json
CHANGED
|
@@ -145,6 +145,15 @@ export interface NitroLocationTracking
|
|
|
145
145
|
getLocationPermissionStatus(): PermissionStatus;
|
|
146
146
|
requestLocationPermission(): Promise<PermissionStatus>;
|
|
147
147
|
|
|
148
|
+
// === Distance Utilities ===
|
|
149
|
+
getDistanceBetween(
|
|
150
|
+
lat1: number,
|
|
151
|
+
lon1: number,
|
|
152
|
+
lat2: number,
|
|
153
|
+
lon2: number
|
|
154
|
+
): number; // meters
|
|
155
|
+
getDistanceToGeofence(regionId: string): number; // meters from last known location to geofence center, -1 if not found
|
|
156
|
+
|
|
148
157
|
// === Notifications ===
|
|
149
158
|
showLocalNotification(title: string, body: string): void;
|
|
150
159
|
updateForegroundNotification(title: string, body: string): void;
|