@nobody-os/react-native-background-geolocation 0.0.0-stage → 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/LICENSE +20 -0
- package/README.md +129 -2
- package/ReactNativeBackgroundGeolocation.podspec +22 -0
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/pakeku/reactnativebackgroundgeolocation/ReactNativeBackgroundGeolocationModule.kt +185 -0
- package/android/src/main/java/com/pakeku/reactnativebackgroundgeolocation/ReactNativeBackgroundGeolocationPackage.kt +30 -0
- package/ios/ReactNativeBackgroundGeolocation.h +5 -0
- package/ios/ReactNativeBackgroundGeolocation.mm +147 -0
- package/lib/module/NativeReactNativeBackgroundGeolocation.js +15 -0
- package/lib/module/NativeReactNativeBackgroundGeolocation.js.map +1 -0
- package/lib/module/geo/filter.js +37 -0
- package/lib/module/geo/filter.js.map +1 -0
- package/lib/module/geo/recorder.js +278 -0
- package/lib/module/geo/recorder.js.map +1 -0
- package/lib/module/index.js +60 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/location.js +71 -0
- package/lib/module/location.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeReactNativeBackgroundGeolocation.d.ts +66 -0
- package/lib/typescript/src/NativeReactNativeBackgroundGeolocation.d.ts.map +1 -0
- package/lib/typescript/src/geo/filter.d.ts +26 -0
- package/lib/typescript/src/geo/filter.d.ts.map +1 -0
- package/lib/typescript/src/geo/recorder.d.ts +132 -0
- package/lib/typescript/src/geo/recorder.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +44 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/location.d.ts +35 -0
- package/lib/typescript/src/location.d.ts.map +1 -0
- package/package.json +144 -4
- package/src/NativeReactNativeBackgroundGeolocation.ts +73 -0
- package/src/geo/filter.ts +62 -0
- package/src/geo/recorder.ts +395 -0
- package/src/index.tsx +97 -0
- package/src/location.ts +93 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { haversineMeters } from "../location.js";
|
|
4
|
+
import { shouldAcceptFix, DEFAULT_FILTER_OPTIONS } from "./filter.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TrackRecorder ingests raw fixes and builds a clean track: total distance,
|
|
8
|
+
* elapsed and moving time, per-kilometer (or per-mile) splits, and stop
|
|
9
|
+
* detection. It is the "Strava brain" of the library, written as pure
|
|
10
|
+
* TypeScript so it can be proven with unit tests and reused by any app
|
|
11
|
+
* built on the native engine.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One continuous stretch of a track, bounded by pauses. When the recorder
|
|
16
|
+
* stays stopped for at least `pauseThresholdMs`, the current segment is
|
|
17
|
+
* closed at the last moving fix and the next moving fix opens a new one.
|
|
18
|
+
* The pause itself belongs to no segment.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Everything an app needs to render a finished (or live) activity. */
|
|
22
|
+
|
|
23
|
+
const DEFAULT_SPLIT_LENGTH = 1000;
|
|
24
|
+
const DEFAULT_STOP_SPEED = 0.5;
|
|
25
|
+
const DEFAULT_PAUSE_THRESHOLD_MS = 180_000;
|
|
26
|
+
export class TrackRecorder {
|
|
27
|
+
fixes = [];
|
|
28
|
+
_distanceMeters = 0;
|
|
29
|
+
_movingMs = 0;
|
|
30
|
+
_elapsedMs = 0;
|
|
31
|
+
_elevationGainMeters = 0;
|
|
32
|
+
_splits = [];
|
|
33
|
+
distanceAtSplitStart = 0;
|
|
34
|
+
timeAtSplitStart = 0;
|
|
35
|
+
completedSegments = [];
|
|
36
|
+
segment = null;
|
|
37
|
+
/** Stopped time accumulated in the current, not-yet-a-pause stop. */
|
|
38
|
+
stopEpisodeMs = 0;
|
|
39
|
+
/**
|
|
40
|
+
* Segment state captured when the current stop began. If the stop turns
|
|
41
|
+
* into a pause, the segment is closed from this snapshot, so the stopped
|
|
42
|
+
* fixes never join the segment they interrupted.
|
|
43
|
+
*/
|
|
44
|
+
stopSnapshot = null;
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
this.filterOptions = options.filter ?? DEFAULT_FILTER_OPTIONS;
|
|
47
|
+
this.splitLengthMeters = options.splitLengthMeters ?? DEFAULT_SPLIT_LENGTH;
|
|
48
|
+
this.stopSpeedThresholdMps = options.stopSpeedThresholdMps ?? DEFAULT_STOP_SPEED;
|
|
49
|
+
this.pauseThresholdMs = options.pauseThresholdMs ?? DEFAULT_PAUSE_THRESHOLD_MS;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Offer a raw fix to the track. Returns true when the fix was accepted
|
|
54
|
+
* and recorded, false when a filter rule dropped it.
|
|
55
|
+
*/
|
|
56
|
+
addFix(fix) {
|
|
57
|
+
const last = this.fixes[this.fixes.length - 1];
|
|
58
|
+
if (!shouldAcceptFix(fix, last, this.filterOptions)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (last) {
|
|
62
|
+
const segmentMeters = haversineMeters(last, fix);
|
|
63
|
+
const segmentMs = fix.timestamp - last.timestamp;
|
|
64
|
+
this._distanceMeters += segmentMeters;
|
|
65
|
+
this._elapsedMs += segmentMs;
|
|
66
|
+
const altitudeDelta = fix.altitude - last.altitude;
|
|
67
|
+
if (altitudeDelta > 0) {
|
|
68
|
+
this._elevationGainMeters += altitudeDelta;
|
|
69
|
+
}
|
|
70
|
+
const impliedSpeed = segmentMs > 0 ? segmentMeters / (segmentMs / 1000) : 0;
|
|
71
|
+
const reportedSpeed = fix.speed >= 0 ? fix.speed : impliedSpeed;
|
|
72
|
+
const pairMoving = reportedSpeed >= this.stopSpeedThresholdMps;
|
|
73
|
+
// Sparse-fix pause: the engine emitted nothing while the user was
|
|
74
|
+
// stopped (stationary fixes are filtered out), so the pause shows up
|
|
75
|
+
// as one long, barely-moving gap before a MOVING fix. (A stopped
|
|
76
|
+
// pair, however long, belongs to the stop-episode accounting below,
|
|
77
|
+
// never to this rule.)
|
|
78
|
+
const isLongPauseGap = pairMoving && segmentMs >= this.pauseThresholdMs && impliedSpeed < this.stopSpeedThresholdMps;
|
|
79
|
+
if (pairMoving && !isLongPauseGap) {
|
|
80
|
+
this._movingMs += segmentMs;
|
|
81
|
+
}
|
|
82
|
+
this.recordSegmentPair(fix, segmentMeters, segmentMs, pairMoving, isLongPauseGap);
|
|
83
|
+
if (this._distanceMeters - this.distanceAtSplitStart >= this.splitLengthMeters) {
|
|
84
|
+
const splitDuration = fix.timestamp - this.timeAtSplitStart;
|
|
85
|
+
const splitDistance = this._distanceMeters - this.distanceAtSplitStart;
|
|
86
|
+
this._splits.push({
|
|
87
|
+
distanceMeters: splitDistance,
|
|
88
|
+
durationMs: splitDuration,
|
|
89
|
+
paceSecondsPerKm: splitDistance > 0 ? splitDuration / 1000 / (splitDistance / 1000) : 0
|
|
90
|
+
});
|
|
91
|
+
this.distanceAtSplitStart = this._distanceMeters;
|
|
92
|
+
this.timeAtSplitStart = fix.timestamp;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
this.timeAtSplitStart = fix.timestamp;
|
|
96
|
+
this.segment = {
|
|
97
|
+
fixCount: 1,
|
|
98
|
+
distanceMeters: 0,
|
|
99
|
+
movingMs: 0,
|
|
100
|
+
startTimestamp: fix.timestamp,
|
|
101
|
+
lastTimestamp: fix.timestamp
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
this.fixes.push(fix);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Fold one accepted pair (previous fix -> this fix) into the segment
|
|
110
|
+
* bookkeeping, closing and reopening segments around pauses.
|
|
111
|
+
*/
|
|
112
|
+
recordSegmentPair(fix, segmentMeters, segmentMs, pairMoving, isLongPauseGap) {
|
|
113
|
+
if (!this.segment) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (isLongPauseGap) {
|
|
117
|
+
// Close the segment at the last fix before the gap (the snapshot if
|
|
118
|
+
// a stop episode was in progress, else the live accumulators) and
|
|
119
|
+
// open a new segment at this fix.
|
|
120
|
+
const closing = this.stopSnapshot ?? this.segment;
|
|
121
|
+
this.completedSegments.push(toTrackSegment(closing));
|
|
122
|
+
this.segment = {
|
|
123
|
+
fixCount: 1,
|
|
124
|
+
distanceMeters: 0,
|
|
125
|
+
movingMs: 0,
|
|
126
|
+
startTimestamp: fix.timestamp,
|
|
127
|
+
lastTimestamp: fix.timestamp
|
|
128
|
+
};
|
|
129
|
+
this.stopEpisodeMs = 0;
|
|
130
|
+
this.stopSnapshot = null;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (pairMoving) {
|
|
134
|
+
if (this.stopSnapshot !== null && this.stopEpisodeMs >= this.pauseThresholdMs) {
|
|
135
|
+
// The stop became a pause: close the segment where movement last
|
|
136
|
+
// happened, and let this fix open a fresh segment. The bridging
|
|
137
|
+
// distance (GPS drift at a standstill) counts toward the track
|
|
138
|
+
// totals but belongs to neither segment.
|
|
139
|
+
this.completedSegments.push(toTrackSegment(this.stopSnapshot));
|
|
140
|
+
this.segment = {
|
|
141
|
+
fixCount: 1,
|
|
142
|
+
distanceMeters: 0,
|
|
143
|
+
movingMs: 0,
|
|
144
|
+
startTimestamp: fix.timestamp,
|
|
145
|
+
lastTimestamp: fix.timestamp
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
this.segment.fixCount += 1;
|
|
149
|
+
this.segment.distanceMeters += segmentMeters;
|
|
150
|
+
this.segment.movingMs += segmentMs;
|
|
151
|
+
this.segment.lastTimestamp = fix.timestamp;
|
|
152
|
+
}
|
|
153
|
+
this.stopEpisodeMs = 0;
|
|
154
|
+
this.stopSnapshot = null;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Stopped pair: tentatively part of the current segment, unless the
|
|
159
|
+
// stop grows into a pause, in which case the snapshot taken here is
|
|
160
|
+
// what gets closed.
|
|
161
|
+
if (this.stopSnapshot === null) {
|
|
162
|
+
this.stopSnapshot = {
|
|
163
|
+
...this.segment
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
this.stopEpisodeMs += segmentMs;
|
|
167
|
+
this.segment.fixCount += 1;
|
|
168
|
+
this.segment.distanceMeters += segmentMeters;
|
|
169
|
+
this.segment.lastTimestamp = fix.timestamp;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Accepted fixes, in order. */
|
|
173
|
+
get points() {
|
|
174
|
+
return [...this.fixes];
|
|
175
|
+
}
|
|
176
|
+
get distanceMeters() {
|
|
177
|
+
return this._distanceMeters;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Wall-clock time from first to last accepted fix, in milliseconds. */
|
|
181
|
+
get elapsedMs() {
|
|
182
|
+
return this._elapsedMs;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Time actually spent moving (stops excluded), in milliseconds. */
|
|
186
|
+
get movingMs() {
|
|
187
|
+
return this._movingMs;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Elapsed minus moving: time spent standing still, in milliseconds. */
|
|
191
|
+
get stoppedMs() {
|
|
192
|
+
return this._elapsedMs - this._movingMs;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** True when the most recent movement looks like a stop. */
|
|
196
|
+
get isStopped() {
|
|
197
|
+
if (this.fixes.length < 2) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
const last = this.fixes[this.fixes.length - 1];
|
|
201
|
+
return last !== undefined && last.speed >= 0 ? last.speed < this.stopSpeedThresholdMps : false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Completed splits so far. */
|
|
205
|
+
get splits() {
|
|
206
|
+
return [...this._splits];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Total climbing, in meters: positive altitude changes only. */
|
|
210
|
+
get elevationGainMeters() {
|
|
211
|
+
return this._elevationGainMeters;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* All segments, finished ones plus the one still in progress. When the
|
|
216
|
+
* recorder is sitting in a pause that has passed the threshold, the
|
|
217
|
+
* interrupted segment is already shown closed at its last moving fix.
|
|
218
|
+
*/
|
|
219
|
+
get segments() {
|
|
220
|
+
const visible = [...this.completedSegments];
|
|
221
|
+
if (this.stopSnapshot !== null && this.stopEpisodeMs >= this.pauseThresholdMs) {
|
|
222
|
+
visible.push(toTrackSegment(this.stopSnapshot));
|
|
223
|
+
} else if (this.segment !== null && this.segment.fixCount > 0) {
|
|
224
|
+
visible.push(toTrackSegment(this.segment));
|
|
225
|
+
}
|
|
226
|
+
return visible;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** One-call snapshot of the whole track, for rendering an activity. */
|
|
230
|
+
summary() {
|
|
231
|
+
const segments = this.segments;
|
|
232
|
+
return {
|
|
233
|
+
distanceMeters: this._distanceMeters,
|
|
234
|
+
elapsedMs: this._elapsedMs,
|
|
235
|
+
movingMs: this._movingMs,
|
|
236
|
+
stoppedMs: this.stoppedMs,
|
|
237
|
+
elevationGainMeters: this._elevationGainMeters,
|
|
238
|
+
averagePaceSecondsPerKm: this.averagePaceSecondsPerKm,
|
|
239
|
+
fixCount: this.fixes.length,
|
|
240
|
+
segmentCount: segments.length,
|
|
241
|
+
segments,
|
|
242
|
+
splits: this.splits
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Average pace over the whole track, seconds per kilometer. */
|
|
247
|
+
get averagePaceSecondsPerKm() {
|
|
248
|
+
if (this._distanceMeters === 0 || this._movingMs === 0) {
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
return this._movingMs / 1000 / (this._distanceMeters / 1000);
|
|
252
|
+
}
|
|
253
|
+
reset() {
|
|
254
|
+
this.fixes = [];
|
|
255
|
+
this._distanceMeters = 0;
|
|
256
|
+
this._movingMs = 0;
|
|
257
|
+
this._elapsedMs = 0;
|
|
258
|
+
this._elevationGainMeters = 0;
|
|
259
|
+
this._splits = [];
|
|
260
|
+
this.distanceAtSplitStart = 0;
|
|
261
|
+
this.timeAtSplitStart = 0;
|
|
262
|
+
this.completedSegments = [];
|
|
263
|
+
this.segment = null;
|
|
264
|
+
this.stopEpisodeMs = 0;
|
|
265
|
+
this.stopSnapshot = null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function toTrackSegment(acc) {
|
|
269
|
+
return {
|
|
270
|
+
startTimestamp: acc.startTimestamp,
|
|
271
|
+
endTimestamp: acc.lastTimestamp,
|
|
272
|
+
durationMs: acc.lastTimestamp - acc.startTimestamp,
|
|
273
|
+
distanceMeters: acc.distanceMeters,
|
|
274
|
+
movingMs: acc.movingMs,
|
|
275
|
+
fixCount: acc.fixCount
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["haversineMeters","shouldAcceptFix","DEFAULT_FILTER_OPTIONS","DEFAULT_SPLIT_LENGTH","DEFAULT_STOP_SPEED","DEFAULT_PAUSE_THRESHOLD_MS","TrackRecorder","fixes","_distanceMeters","_movingMs","_elapsedMs","_elevationGainMeters","_splits","distanceAtSplitStart","timeAtSplitStart","completedSegments","segment","stopEpisodeMs","stopSnapshot","constructor","options","filterOptions","filter","splitLengthMeters","stopSpeedThresholdMps","pauseThresholdMs","addFix","fix","last","length","segmentMeters","segmentMs","timestamp","altitudeDelta","altitude","impliedSpeed","reportedSpeed","speed","pairMoving","isLongPauseGap","recordSegmentPair","splitDuration","splitDistance","push","distanceMeters","durationMs","paceSecondsPerKm","fixCount","movingMs","startTimestamp","lastTimestamp","closing","toTrackSegment","points","elapsedMs","stoppedMs","isStopped","undefined","splits","elevationGainMeters","segments","visible","summary","averagePaceSecondsPerKm","segmentCount","reset","acc","endTimestamp"],"sourceRoot":"../../../src","sources":["geo/recorder.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAQ,gBAAa;AAC7C,SACEC,eAAe,EACfC,sBAAsB,QAGjB,aAAU;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;;AAgBA;;AAgCA,MAAMC,oBAAoB,GAAG,IAAI;AACjC,MAAMC,kBAAkB,GAAG,GAAG;AAC9B,MAAMC,0BAA0B,GAAG,OAAO;AAU1C,OAAO,MAAMC,aAAa,CAAC;EAMjBC,KAAK,GAAe,EAAE;EACtBC,eAAe,GAAG,CAAC;EACnBC,SAAS,GAAG,CAAC;EACbC,UAAU,GAAG,CAAC;EACdC,oBAAoB,GAAG,CAAC;EACxBC,OAAO,GAAY,EAAE;EACrBC,oBAAoB,GAAG,CAAC;EACxBC,gBAAgB,GAAG,CAAC;EAEpBC,iBAAiB,GAAmB,EAAE;EACtCC,OAAO,GAA+B,IAAI;EAClD;EACQC,aAAa,GAAG,CAAC;EACzB;AACF;AACA;AACA;AACA;EACUC,YAAY,GAA+B,IAAI;EAEvDC,WAAWA,CAACC,OAAwB,GAAG,CAAC,CAAC,EAAE;IACzC,IAAI,CAACC,aAAa,GAAGD,OAAO,CAACE,MAAM,IAAIpB,sBAAsB;IAC7D,IAAI,CAACqB,iBAAiB,GAAGH,OAAO,CAACG,iBAAiB,IAAIpB,oBAAoB;IAC1E,IAAI,CAACqB,qBAAqB,GACxBJ,OAAO,CAACI,qBAAqB,IAAIpB,kBAAkB;IACrD,IAAI,CAACqB,gBAAgB,GACnBL,OAAO,CAACK,gBAAgB,IAAIpB,0BAA0B;EAC1D;;EAEA;AACF;AACA;AACA;EACEqB,MAAMA,CAACC,GAAa,EAAW;IAC7B,MAAMC,IAAI,GAAG,IAAI,CAACrB,KAAK,CAAC,IAAI,CAACA,KAAK,CAACsB,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,CA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C,oBAAoB,GAAG,CAAC;IAC7B,IAAI,CAACC,OAAO,GAAG,EAAE;IACjB,IAAI,CAACC,oBAAoB,GAAG,CAAC;IAC7B,IAAI,CAACC,gBAAgB,GAAG,CAAC;IACzB,IAAI,CAACC,iBAAiB,GAAG,EAAE;IAC3B,IAAI,CAACC,OAAO,GAAG,IAAI;IACnB,IAAI,CAACC,aAAa,GAAG,CAAC;IACtB,IAAI,CAACC,YAAY,GAAG,IAAI;EAC1B;AACF;AAEA,SAASkC,cAAcA,CAACc,GAAwB,EAAgB;EAC9D,OAAO;IACLjB,cAAc,EAAEiB,GAAG,CAACjB,cAAc;IAClCkB,YAAY,EAAED,GAAG,CAAChB,aAAa;IAC/BL,UAAU,EAAEqB,GAAG,CAAChB,aAAa,GAAGgB,GAAG,CAACjB,cAAc;IAClDL,cAAc,EAAEsB,GAAG,CAACtB,cAAc;IAClCI,QAAQ,EAAEkB,GAAG,CAAClB,QAAQ;IACtBD,QAAQ,EAAEmB,GAAG,CAACnB;EAChB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeBackgroundGeolocation from "./NativeReactNativeBackgroundGeolocation.js";
|
|
4
|
+
export { haversineMeters, totalDistanceMeters, filterByAccuracy, durationSeconds, averagePaceMinPerKm } from "./location.js";
|
|
5
|
+
export { shouldAcceptFix, hasAcceptableAccuracy, isChronological, isFarEnough, DEFAULT_FILTER_OPTIONS } from "./geo/filter.js";
|
|
6
|
+
export { TrackRecorder } from "./geo/recorder.js";
|
|
7
|
+
/**
|
|
8
|
+
* Start background location tracking.
|
|
9
|
+
*
|
|
10
|
+
* The app is responsible for holding location permission (and, for true
|
|
11
|
+
* background tracking, the background location permission) before calling
|
|
12
|
+
* this. The promise rejects with code E_PERMISSION when it does not.
|
|
13
|
+
*/
|
|
14
|
+
export function start(config = {}) {
|
|
15
|
+
return NativeBackgroundGeolocation.start(config);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Stop tracking and release the native engine. */
|
|
19
|
+
export function stop() {
|
|
20
|
+
return NativeBackgroundGeolocation.stop();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One-shot position query: ask the OS where the device is right now,
|
|
25
|
+
* without starting continuous tracking.
|
|
26
|
+
*/
|
|
27
|
+
export function getCurrentPosition() {
|
|
28
|
+
return NativeBackgroundGeolocation.getCurrentPosition();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Whether native tracking is currently running. */
|
|
32
|
+
export function isTracking() {
|
|
33
|
+
return NativeBackgroundGeolocation.isTracking();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to fixes while tracking. Returns a subscription to remove.
|
|
38
|
+
*
|
|
39
|
+
* With codegen EventEmitter properties, the spec property itself is the
|
|
40
|
+
* subscribe function. Do NOT route this through NativeEventEmitter: its
|
|
41
|
+
* legacy addListener call throws inside the new-architecture TurboModule
|
|
42
|
+
* invocation layer and aborts the app (found the hard way, build 7).
|
|
43
|
+
*/
|
|
44
|
+
export function addLocationListener(listener) {
|
|
45
|
+
return NativeBackgroundGeolocation.onLocation(listener);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Subscribe to native engine errors. Returns a subscription to remove. */
|
|
49
|
+
export function addErrorListener(listener) {
|
|
50
|
+
return NativeBackgroundGeolocation.onError(listener);
|
|
51
|
+
}
|
|
52
|
+
export default {
|
|
53
|
+
start,
|
|
54
|
+
stop,
|
|
55
|
+
getCurrentPosition,
|
|
56
|
+
isTracking,
|
|
57
|
+
addLocationListener,
|
|
58
|
+
addErrorListener
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeBackgroundGeolocation","haversineMeters","totalDistanceMeters","filterByAccuracy","durationSeconds","averagePaceMinPerKm","shouldAcceptFix","hasAcceptableAccuracy","isChronological","isFarEnough","DEFAULT_FILTER_OPTIONS","TrackRecorder","start","config","stop","getCurrentPosition","isTracking","addLocationListener","listener","onLocation","addErrorListener","onError"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,2BAA2B,MAI3B,6CAA0C;AAIjD,SACEC,eAAe,EACfC,mBAAmB,EACnBC,gBAAgB,EAChBC,eAAe,EACfC,mBAAmB,QAGd,eAAY;AACnB,SACEC,eAAe,EACfC,qBAAqB,EACrBC,eAAe,EACfC,WAAW,EACXC,sBAAsB,QAGjB,iBAAc;AACrB,SACEC,aAAa,QAMR,mBAAgB;AAMvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,KAAKA,CAACC,MAAyB,GAAG,CAAC,CAAC,EAAiB;EACnE,OAAOb,2BAA2B,CAACY,KAAK,CAACC,MAAM,CAAC;AAClD;;AAEA;AACA,OAAO,SAASC,IAAIA,CAAA,EAAkB;EACpC,OAAOd,2BAA2B,CAACc,IAAI,CAAC,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAA,EAAyB;EACzD,OAAOf,2BAA2B,CAACe,kBAAkB,CAAC,CAAC;AACzD;;AAEA;AACA,OAAO,SAASC,UAAUA,CAAA,EAAqB;EAC7C,OAAOhB,2BAA2B,CAACgB,UAAU,CAAC,CAAC;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CACjCC,QAAoC,EACd;EACtB,OAAOlB,2BAA2B,CAACmB,UAAU,CAACD,QAAQ,CAAC;AACzD;;AAEA;AACA,OAAO,SAASE,gBAAgBA,CAC9BF,QAA2C,EACrB;EACtB,OAAOlB,2BAA2B,CAACqB,OAAO,CAACH,QAAQ,CAAC;AACtD;AAEA,eAAe;EACbN,KAAK;EACLE,IAAI;EACJC,kBAAkB;EAClBC,UAAU;EACVC,mBAAmB;EACnBG;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Pure location math for @nobody-os/react-native-background-geolocation.
|
|
4
|
+
//
|
|
5
|
+
// No React Native imports here on purpose: these are pure functions, so they
|
|
6
|
+
// are testable with Jest on any machine (including Windows, no phone, no
|
|
7
|
+
// emulator) and they are the engine the native bridge feeds into.
|
|
8
|
+
// Earth radius 6,371,000 m (mean radius), haversine formula.
|
|
9
|
+
|
|
10
|
+
const EARTH_RADIUS_M = 6_371_000;
|
|
11
|
+
function toRadians(degrees) {
|
|
12
|
+
return degrees * Math.PI / 180;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Anything with a latitude and a longitude: a fix, a waypoint, a pin. */
|
|
16
|
+
|
|
17
|
+
/** Great-circle distance between two coordinates, in metres. */
|
|
18
|
+
export function haversineMeters(a, b) {
|
|
19
|
+
const dLat = toRadians(b.latitude - a.latitude);
|
|
20
|
+
const dLon = toRadians(b.longitude - a.longitude);
|
|
21
|
+
const lat1 = toRadians(a.latitude);
|
|
22
|
+
const lat2 = toRadians(b.latitude);
|
|
23
|
+
const h = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
24
|
+
return 2 * EARTH_RADIUS_M * Math.asin(Math.sqrt(h));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Sum of haversine distances between consecutive points, in metres. */
|
|
28
|
+
export function totalDistanceMeters(fixes) {
|
|
29
|
+
let total = 0;
|
|
30
|
+
for (let i = 1; i < fixes.length; i += 1) {
|
|
31
|
+
const prev = fixes[i - 1];
|
|
32
|
+
const curr = fixes[i];
|
|
33
|
+
if (prev !== undefined && curr !== undefined) {
|
|
34
|
+
total += haversineMeters(prev, curr);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return total;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Drop fixes whose reported accuracy is worse than `maxAccuracyM`.
|
|
42
|
+
* Fixes with no accuracy reading are kept: the OS gave us no reason to
|
|
43
|
+
* distrust them. Default 50 m matches a typical running-track tolerance.
|
|
44
|
+
*/
|
|
45
|
+
export function filterByAccuracy(fixes, maxAccuracyM = 50) {
|
|
46
|
+
return fixes.filter(fix => fix.accuracy === undefined || fix.accuracy <= maxAccuracyM);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Elapsed time between the first and last fix, in seconds. */
|
|
50
|
+
export function durationSeconds(fixes) {
|
|
51
|
+
const first = fixes[0];
|
|
52
|
+
const last = fixes[fixes.length - 1];
|
|
53
|
+
if (first === undefined || last === undefined) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
return Math.max(0, (last.timestampMs - first.timestampMs) / 1000);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Average pace in minutes per kilometre. Returns null when there is no
|
|
61
|
+
* usable distance or duration (avoids a divide-by-zero pace of Infinity).
|
|
62
|
+
*/
|
|
63
|
+
export function averagePaceMinPerKm(fixes) {
|
|
64
|
+
const distanceKm = totalDistanceMeters(fixes) / 1000;
|
|
65
|
+
const durationMin = durationSeconds(fixes) / 60;
|
|
66
|
+
if (distanceKm <= 0 || durationMin <= 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return durationMin / distanceKm;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EARTH_RADIUS_M","toRadians","degrees","Math","PI","haversineMeters","a","b","dLat","latitude","dLon","longitude","lat1","lat2","h","sin","cos","asin","sqrt","totalDistanceMeters","fixes","total","i","length","prev","curr","undefined","filterByAccuracy","maxAccuracyM","filter","fix","accuracy","durationSeconds","first","last","max","timestampMs","averagePaceMinPerKm","distanceKm","durationMin"],"sourceRoot":"../../src","sources":["location.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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Codegen spec for the ReactNativeBackgroundGeolocation TurboModule.
|
|
5
|
+
*
|
|
6
|
+
* This file is the contract between TypeScript and the native engines.
|
|
7
|
+
* React Native's codegen generates the Kotlin and Objective-C++ bindings
|
|
8
|
+
* from the types declared here, so every public type must stay
|
|
9
|
+
* codegen-compatible (plain object type aliases, no interfaces for data).
|
|
10
|
+
*/
|
|
11
|
+
export type GeolocationConfig = {
|
|
12
|
+
/**
|
|
13
|
+
* Accuracy profile: 'high' (GPS, for run/walk tracking),
|
|
14
|
+
* 'balanced' (default), or 'low' (network/cell, battery-sipping).
|
|
15
|
+
*/
|
|
16
|
+
desiredAccuracy?: string;
|
|
17
|
+
/** Minimum distance in meters between fixes. Default 10. */
|
|
18
|
+
distanceFilter?: number;
|
|
19
|
+
/** Android: desired interval in milliseconds between fixes. Default 5000. */
|
|
20
|
+
interval?: number;
|
|
21
|
+
/** Android: fastest interval in milliseconds the app will accept. Default 2000. */
|
|
22
|
+
fastestInterval?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Minutes of detected stillness after which tracking pauses itself
|
|
25
|
+
* (stop detection). Set to 0 to disable. Default 5.
|
|
26
|
+
*/
|
|
27
|
+
stopTimeout?: number;
|
|
28
|
+
/** Verbose native logging while developing. Default false. */
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type LocationFix = {
|
|
32
|
+
latitude: number;
|
|
33
|
+
longitude: number;
|
|
34
|
+
/** Horizontal accuracy in meters (radius of uncertainty). */
|
|
35
|
+
accuracy: number;
|
|
36
|
+
/** Altitude in meters above sea level, or -1 when unavailable. */
|
|
37
|
+
altitude: number;
|
|
38
|
+
/** Speed in meters per second, or -1 when unavailable. */
|
|
39
|
+
speed: number;
|
|
40
|
+
/** Heading in degrees clockwise from north, or -1 when unavailable. */
|
|
41
|
+
heading: number;
|
|
42
|
+
/** Milliseconds since the Unix epoch, as reported by the OS. */
|
|
43
|
+
timestamp: number;
|
|
44
|
+
};
|
|
45
|
+
export type GeolocationError = {
|
|
46
|
+
/** 1 = permission denied, 2 = position unavailable, 3 = timeout. */
|
|
47
|
+
code: number;
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
export interface Spec extends TurboModule {
|
|
51
|
+
/** Start background tracking with the given configuration. */
|
|
52
|
+
start(config: GeolocationConfig): Promise<void>;
|
|
53
|
+
/** Stop tracking and release native resources. */
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
/** One-shot position query: ask the OS where the device is right now. */
|
|
56
|
+
getCurrentPosition(): Promise<LocationFix>;
|
|
57
|
+
/** Whether native tracking is currently running. */
|
|
58
|
+
isTracking(): Promise<boolean>;
|
|
59
|
+
/** Fires for every accepted fix while tracking. */
|
|
60
|
+
readonly onLocation: EventEmitter<LocationFix>;
|
|
61
|
+
/** Fires when the native engine reports an error. */
|
|
62
|
+
readonly onError: EventEmitter<GeolocationError>;
|
|
63
|
+
}
|
|
64
|
+
declare const _default: Spec;
|
|
65
|
+
export default _default;
|
|
66
|
+
//# sourceMappingURL=NativeReactNativeBackgroundGeolocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeReactNativeBackgroundGeolocation.d.ts","sourceRoot":"","sources":["../../../src/NativeReactNativeBackgroundGeolocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAE9E;;;;;;;GAOG;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D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import { type Coordinate } from '../location.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fix acceptance rules. Raw GPS is noisy: fixes arrive with poor accuracy,
|
|
4
|
+
* out of order, or jittering around a point while the device stands still.
|
|
5
|
+
* A fix is only worth recording when it passes every rule below.
|
|
6
|
+
*/
|
|
7
|
+
export type FilterOptions = {
|
|
8
|
+
/** Fixes with accuracy worse (larger) than this, in meters, are dropped. */
|
|
9
|
+
maxAccuracyMeters: number;
|
|
10
|
+
/** Fixes closer than this to the last accepted fix, in meters, are dropped. */
|
|
11
|
+
minDistanceMeters: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const DEFAULT_FILTER_OPTIONS: FilterOptions;
|
|
14
|
+
export type FixLike = Coordinate & {
|
|
15
|
+
accuracy: number;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
};
|
|
18
|
+
/** True when the fix's own reported accuracy is good enough to trust. */
|
|
19
|
+
export declare function hasAcceptableAccuracy(fix: FixLike, options: FilterOptions): boolean;
|
|
20
|
+
/** True when the fix is newer than the last accepted one (no time travel). */
|
|
21
|
+
export declare function isChronological(fix: FixLike, last?: FixLike): boolean;
|
|
22
|
+
/** True when the fix moved far enough from the last accepted fix to matter. */
|
|
23
|
+
export declare function isFarEnough(fix: FixLike, last: FixLike | undefined, options: FilterOptions): boolean;
|
|
24
|
+
/** All rules combined: should this fix be recorded? */
|
|
25
|
+
export declare function shouldAcceptFix(fix: FixLike, last: FixLike | undefined, options?: FilterOptions): boolean;
|
|
26
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../src/geo/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,gBAAa,CAAC;AAE/D;;;;GAIG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,aAGpC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,aAAa,GACrB,OAAO,CAET;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAErE;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAKT;AAED,uDAAuD;AACvD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,OAAO,GAAE,aAAsC,GAC9C,OAAO,CAMT"}
|