react-native-nitro-location-tracking 0.1.1 → 0.1.2
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/android/src/main/java/com/margelo/nitro/nitrolocationtracking/LocationForegroundService.kt
CHANGED
|
@@ -26,13 +26,15 @@ class LocationForegroundService : Service() {
|
|
|
26
26
|
(getSystemService(NOTIFICATION_SERVICE) as NotificationManager)
|
|
27
27
|
.createNotificationChannel(channel)
|
|
28
28
|
}
|
|
29
|
+
// Must call startForeground immediately to avoid ForegroundServiceDidNotStartInTimeException
|
|
30
|
+
startForeground(NOTIFICATION_ID, buildNotification("Location Active", "Tracking your location"))
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
32
34
|
val title = intent?.getStringExtra("title") ?: "Location Active"
|
|
33
35
|
val text = intent?.getStringExtra("text") ?: "Tracking your location"
|
|
34
36
|
when (intent?.action) {
|
|
35
|
-
ACTION_START -> startForeground(
|
|
37
|
+
ACTION_START, null -> startForeground(
|
|
36
38
|
NOTIFICATION_ID, buildNotification(title, text))
|
|
37
39
|
ACTION_STOP -> {
|
|
38
40
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
package/ios/LocationEngine.swift
CHANGED
|
@@ -48,9 +48,26 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
48
48
|
var isTracking: Bool { tracking }
|
|
49
49
|
|
|
50
50
|
func getCurrentLocation(completion: @escaping (LocationData?) -> Void) {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// If we already have a recent location, return it immediately
|
|
52
|
+
if let lastLocation = locationManager.location {
|
|
53
|
+
let age: TimeInterval = Swift.abs(lastLocation.timestamp.timeIntervalSinceNow)
|
|
54
|
+
if age < 10.0 {
|
|
55
|
+
let data = LocationData(
|
|
56
|
+
latitude: lastLocation.coordinate.latitude,
|
|
57
|
+
longitude: lastLocation.coordinate.longitude,
|
|
58
|
+
altitude: lastLocation.altitude,
|
|
59
|
+
speed: max(lastLocation.speed, 0),
|
|
60
|
+
bearing: max(lastLocation.course, 0),
|
|
61
|
+
accuracy: lastLocation.horizontalAccuracy,
|
|
62
|
+
timestamp: lastLocation.timestamp.timeIntervalSince1970 * 1000
|
|
63
|
+
)
|
|
64
|
+
completion(data)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Otherwise request a fresh location
|
|
53
69
|
pendingLocationCompletion = completion
|
|
70
|
+
locationManager.requestLocation()
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
private var pendingLocationCompletion: ((LocationData?) -> Void)?
|
|
@@ -97,50 +114,3 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
97
114
|
}
|
|
98
115
|
}
|
|
99
116
|
|
|
100
|
-
//// Simple struct to pass location data between components
|
|
101
|
-
//struct LocationData {
|
|
102
|
-
// let latitude: Double
|
|
103
|
-
// let longitude: Double
|
|
104
|
-
// let altitude: Double
|
|
105
|
-
// let speed: Double
|
|
106
|
-
// let bearing: Double
|
|
107
|
-
// let accuracy: Double
|
|
108
|
-
// let timestamp: Double
|
|
109
|
-
//
|
|
110
|
-
// var id: String = ""
|
|
111
|
-
//
|
|
112
|
-
// func toJSON() -> [String: Any] {
|
|
113
|
-
// return [
|
|
114
|
-
// "latitude": latitude,
|
|
115
|
-
// "longitude": longitude,
|
|
116
|
-
// "altitude": altitude,
|
|
117
|
-
// "speed": speed,
|
|
118
|
-
// "bearing": bearing,
|
|
119
|
-
// "accuracy": accuracy,
|
|
120
|
-
// "timestamp": timestamp
|
|
121
|
-
// ]
|
|
122
|
-
// }
|
|
123
|
-
//}
|
|
124
|
-
//
|
|
125
|
-
//// Config structs
|
|
126
|
-
//struct LocationConfig {
|
|
127
|
-
// let desiredAccuracy: String
|
|
128
|
-
// let distanceFilter: Double
|
|
129
|
-
// let intervalMs: Double
|
|
130
|
-
// let fastestIntervalMs: Double
|
|
131
|
-
// let stopTimeout: Double
|
|
132
|
-
// let stopOnTerminate: Bool
|
|
133
|
-
// let startOnBoot: Bool
|
|
134
|
-
// let foregroundNotificationTitle: String
|
|
135
|
-
// let foregroundNotificationText: String
|
|
136
|
-
//}
|
|
137
|
-
//
|
|
138
|
-
//struct ConnectionConfig {
|
|
139
|
-
// let wsUrl: String
|
|
140
|
-
// let restUrl: String
|
|
141
|
-
// let authToken: String
|
|
142
|
-
// let reconnectIntervalMs: Double
|
|
143
|
-
// let maxReconnectAttempts: Double
|
|
144
|
-
// let batchSize: Double
|
|
145
|
-
// let syncIntervalMs: Double
|
|
146
|
-
//}
|
package/package.json
CHANGED