@nobody-os/react-native-background-geolocation 0.0.0-stage → 0.1.1

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.
Files changed (37) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +127 -2
  3. package/ReactNativeBackgroundGeolocation.podspec +22 -0
  4. package/android/build.gradle +36 -0
  5. package/android/src/main/AndroidManifest.xml +9 -0
  6. package/android/src/main/java/com/pakeku/reactnativebackgroundgeolocation/ReactNativeBackgroundGeolocationModule.kt +185 -0
  7. package/android/src/main/java/com/pakeku/reactnativebackgroundgeolocation/ReactNativeBackgroundGeolocationPackage.kt +30 -0
  8. package/ios/ReactNativeBackgroundGeolocation.h +5 -0
  9. package/ios/ReactNativeBackgroundGeolocation.mm +147 -0
  10. package/lib/module/NativeReactNativeBackgroundGeolocation.js +15 -0
  11. package/lib/module/NativeReactNativeBackgroundGeolocation.js.map +1 -0
  12. package/lib/module/geo/filter.js +37 -0
  13. package/lib/module/geo/filter.js.map +1 -0
  14. package/lib/module/geo/recorder.js +121 -0
  15. package/lib/module/geo/recorder.js.map +1 -0
  16. package/lib/module/index.js +60 -0
  17. package/lib/module/index.js.map +1 -0
  18. package/lib/module/location.js +71 -0
  19. package/lib/module/location.js.map +1 -0
  20. package/lib/module/package.json +1 -0
  21. package/lib/typescript/package.json +1 -0
  22. package/lib/typescript/src/NativeReactNativeBackgroundGeolocation.d.ts +66 -0
  23. package/lib/typescript/src/NativeReactNativeBackgroundGeolocation.d.ts.map +1 -0
  24. package/lib/typescript/src/geo/filter.d.ts +26 -0
  25. package/lib/typescript/src/geo/filter.d.ts.map +1 -0
  26. package/lib/typescript/src/geo/recorder.d.ts +65 -0
  27. package/lib/typescript/src/geo/recorder.d.ts.map +1 -0
  28. package/lib/typescript/src/index.d.ts +44 -0
  29. package/lib/typescript/src/index.d.ts.map +1 -0
  30. package/lib/typescript/src/location.d.ts +35 -0
  31. package/lib/typescript/src/location.d.ts.map +1 -0
  32. package/package.json +144 -4
  33. package/src/NativeReactNativeBackgroundGeolocation.ts +73 -0
  34. package/src/geo/filter.ts +62 -0
  35. package/src/geo/recorder.ts +170 -0
  36. package/src/index.tsx +95 -0
  37. package/src/location.ts +93 -0
@@ -0,0 +1,121 @@
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
+ const DEFAULT_SPLIT_LENGTH = 1000;
15
+ const DEFAULT_STOP_SPEED = 0.5;
16
+ export class TrackRecorder {
17
+ fixes = [];
18
+ _distanceMeters = 0;
19
+ _movingMs = 0;
20
+ _elapsedMs = 0;
21
+ _splits = [];
22
+ distanceAtSplitStart = 0;
23
+ timeAtSplitStart = 0;
24
+ constructor(options = {}) {
25
+ this.filterOptions = options.filter ?? DEFAULT_FILTER_OPTIONS;
26
+ this.splitLengthMeters = options.splitLengthMeters ?? DEFAULT_SPLIT_LENGTH;
27
+ this.stopSpeedThresholdMps = options.stopSpeedThresholdMps ?? DEFAULT_STOP_SPEED;
28
+ }
29
+
30
+ /**
31
+ * Offer a raw fix to the track. Returns true when the fix was accepted
32
+ * and recorded, false when a filter rule dropped it.
33
+ */
34
+ addFix(fix) {
35
+ const last = this.fixes[this.fixes.length - 1];
36
+ if (!shouldAcceptFix(fix, last, this.filterOptions)) {
37
+ return false;
38
+ }
39
+ if (last) {
40
+ const segmentMeters = haversineMeters(last, fix);
41
+ const segmentMs = fix.timestamp - last.timestamp;
42
+ this._distanceMeters += segmentMeters;
43
+ this._elapsedMs += segmentMs;
44
+ const impliedSpeed = segmentMs > 0 ? segmentMeters / (segmentMs / 1000) : 0;
45
+ const reportedSpeed = fix.speed >= 0 ? fix.speed : impliedSpeed;
46
+ if (reportedSpeed >= this.stopSpeedThresholdMps) {
47
+ this._movingMs += segmentMs;
48
+ }
49
+ if (this._distanceMeters - this.distanceAtSplitStart >= this.splitLengthMeters) {
50
+ const splitDuration = fix.timestamp - this.timeAtSplitStart;
51
+ const splitDistance = this._distanceMeters - this.distanceAtSplitStart;
52
+ this._splits.push({
53
+ distanceMeters: splitDistance,
54
+ durationMs: splitDuration,
55
+ paceSecondsPerKm: splitDistance > 0 ? splitDuration / 1000 / (splitDistance / 1000) : 0
56
+ });
57
+ this.distanceAtSplitStart = this._distanceMeters;
58
+ this.timeAtSplitStart = fix.timestamp;
59
+ }
60
+ } else {
61
+ this.timeAtSplitStart = fix.timestamp;
62
+ }
63
+ this.fixes.push(fix);
64
+ return true;
65
+ }
66
+
67
+ /** Accepted fixes, in order. */
68
+ get points() {
69
+ return [...this.fixes];
70
+ }
71
+ get distanceMeters() {
72
+ return this._distanceMeters;
73
+ }
74
+
75
+ /** Wall-clock time from first to last accepted fix, in milliseconds. */
76
+ get elapsedMs() {
77
+ return this._elapsedMs;
78
+ }
79
+
80
+ /** Time actually spent moving (stops excluded), in milliseconds. */
81
+ get movingMs() {
82
+ return this._movingMs;
83
+ }
84
+
85
+ /** Elapsed minus moving: time spent standing still, in milliseconds. */
86
+ get stoppedMs() {
87
+ return this._elapsedMs - this._movingMs;
88
+ }
89
+
90
+ /** True when the most recent movement looks like a stop. */
91
+ get isStopped() {
92
+ if (this.fixes.length < 2) {
93
+ return true;
94
+ }
95
+ const last = this.fixes[this.fixes.length - 1];
96
+ return last !== undefined && last.speed >= 0 ? last.speed < this.stopSpeedThresholdMps : false;
97
+ }
98
+
99
+ /** Completed splits so far. */
100
+ get splits() {
101
+ return [...this._splits];
102
+ }
103
+
104
+ /** Average pace over the whole track, seconds per kilometer. */
105
+ get averagePaceSecondsPerKm() {
106
+ if (this._distanceMeters === 0 || this._movingMs === 0) {
107
+ return 0;
108
+ }
109
+ return this._movingMs / 1000 / (this._distanceMeters / 1000);
110
+ }
111
+ reset() {
112
+ this.fixes = [];
113
+ this._distanceMeters = 0;
114
+ this._movingMs = 0;
115
+ this._elapsedMs = 0;
116
+ this._splits = [];
117
+ this.distanceAtSplitStart = 0;
118
+ this.timeAtSplitStart = 0;
119
+ }
120
+ }
121
+ //# sourceMappingURL=recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["haversineMeters","shouldAcceptFix","DEFAULT_FILTER_OPTIONS","DEFAULT_SPLIT_LENGTH","DEFAULT_STOP_SPEED","TrackRecorder","fixes","_distanceMeters","_movingMs","_elapsedMs","_splits","distanceAtSplitStart","timeAtSplitStart","constructor","options","filterOptions","filter","splitLengthMeters","stopSpeedThresholdMps","addFix","fix","last","length","segmentMeters","segmentMs","timestamp","impliedSpeed","reportedSpeed","speed","splitDuration","splitDistance","push","distanceMeters","durationMs","paceSecondsPerKm","points","elapsedMs","movingMs","stoppedMs","isStopped","undefined","splits","averagePaceSecondsPerKm","reset"],"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;;AA2BA,MAAMC,oBAAoB,GAAG,IAAI;AACjC,MAAMC,kBAAkB,GAAG,GAAG;AAE9B,OAAO,MAAMC,aAAa,CAAC;EAKjBC,KAAK,GAAe,EAAE;EACtBC,eAAe,GAAG,CAAC;EACnBC,SAAS,GAAG,CAAC;EACbC,UAAU,GAAG,CAAC;EACdC,OAAO,GAAY,EAAE;EACrBC,oBAAoB,GAAG,CAAC;EACxBC,gBAAgB,GAAG,CAAC;EAE5BC,WAAWA,CAACC,OAAwB,GAAG,CAAC,CAAC,EAAE;IACzC,IAAI,CAACC,aAAa,GAAGD,OAAO,CAACE,MAAM,IAAId,sBAAsB;IAC7D,IAAI,CAACe,iBAAiB,GAAGH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AO,CAAC,GAAG,IAAI,CAAC/B,OAAO,CAAC;EAC1B;;EAEA;EACA,IAAIgC,uBAAuBA,CAAA,EAAW;IACpC,IAAI,IAAI,CAACnC,eAAe,KAAK,CAAC,IAAI,IAAI,CAACC,SAAS,KAAK,CAAC,EAAE;MACtD,OAAO,CAAC;IACV;IACA,OAAO,IAAI,CAACA,SAAS,GAAG,IAAI,IAAI,IAAI,CAACD,eAAe,GAAG,IAAI,CAAC;EAC9D;EAEAoC,KAAKA,CAAA,EAAS;IACZ,IAAI,CAACrC,KAAK,GAAG,EAAE;IACf,IAAI,CAACC,eAAe,GAAG,CAAC;IACxB,IAAI,CAACC,SAAS,GAAG,CAAC;IAClB,IAAI,CAACC,UAAU,GAAG,CAAC;IACnB,IAAI,CAACC,OAAO,GAAG,EAAE;IACjB,IAAI,CAACC,oBAAoB,GAAG,CAAC;IAC7B,IAAI,CAACC,gBAAgB,GAAG,CAAC;EAC3B;AACF","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,QAIR,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.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAeA,MAAMA,cAAc,GAAG,SAAS;AAEhC,SAASC,SAASA,CAACC,OAAe,EAAU;EAC1C,OAAQA,OAAO,GAAGC,IAAI,CAACC,EAAE,GAAI,GAAG;AAClC;;AAEA;;AAMA;AACA,OAAO,SAASC,eAAeA,CAACC,CAAa,EAAEC,CAAa,EAAU;EACpE,MAAMC,IAAI,GAAGP,SAAS,CAACM,CAAC,CAACE,QAAQ,GAAGH,CAAC,CAACG,QAAQ,CAAC;EAC/C,MAAMC,IAAI,GAAGT,SAAS,CAACM,CAAC,CAACI,SAAS,GAAGL,CAAC,CAACK,SAAS,CAAC;EACjD,MAAMC,IAAI,GAAGX,SAAS,CAACK,CAAC,CAACG,QAAQ,CAAC;EAClC,MAAMI,IAAI,GAAGZ,SAAS,CAACM,CAAC,CAACE,QAAQ,CAAC;EAClC,MAAMK,CAAC,GACLX,IAAI,CAACY,GAAG,CAACP,IAAI,GAAG,CAAC,CAAC,GAAGL,IAAI,CAACY,GAAG,CAACP,IAAI,GAAG,CAAC,CAAC,GACvCL,IAAI,CAACa,GAAG,CAACJ,IAAI,CAAC,GAAGT,IAAI,CAACa,GAAG,CAACH,IAAI,CAAC,GAAGV,IAAI,CAACY,GAAG,CAACL,IAAI,GAAG,CAAC,CAAC,GAAGP,IAAI,CAACY,GAAG,CAACL,IAAI,GAAG,CAAC,CAAC;EAC3E,OAAO,CAAC,GAAGV,cAAc,GAAGG,IAAI,CAACc,IAAI,CAACd,IAAI,CAACe,IAAI,CAACJ,CAAC,CAAC,CAAC;AACrD;;AAEA;AACA,OAAO,SAASK,mBAAmBA,CAACC,KAA4B,EAAU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AAE;EAC/C,IAAIkB,UAAU,IAAI,CAAC,IAAIC,WAAW,IAAI,CAAC,EAAE;IACvC,OAAO,IAAI;EACb;EACA,OAAOA,WAAW,GAAGD,UAAU;AACjC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -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,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,8DAA8D;IAC9D,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,kDAAkD;IAClD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,yEAAyE;IACzE,kBAAkB,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,oDAAoD;IACpD,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE/B,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IAC/C,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC;CAClD;;AAED,wBAEE"}
@@ -0,0 +1,26 @@
1
+ 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"}
@@ -0,0 +1,65 @@
1
+ import { type FilterOptions, type FixLike } from './filter.js';
2
+ /**
3
+ * TrackRecorder ingests raw fixes and builds a clean track: total distance,
4
+ * elapsed and moving time, per-kilometer (or per-mile) splits, and stop
5
+ * detection. It is the "Strava brain" of the library, written as pure
6
+ * TypeScript so it can be proven with unit tests and reused by any app
7
+ * built on the native engine.
8
+ */
9
+ export type TrackFix = FixLike & {
10
+ altitude: number;
11
+ speed: number;
12
+ };
13
+ export type Split = {
14
+ /** Split length in meters (1000 unless a custom length was configured). */
15
+ distanceMeters: number;
16
+ /** Duration of this split in milliseconds. */
17
+ durationMs: number;
18
+ /** Average pace for the split, seconds per kilometer. */
19
+ paceSecondsPerKm: number;
20
+ };
21
+ export type RecorderOptions = {
22
+ filter?: FilterOptions;
23
+ /** Length of each split in meters. Default 1000 (per-kilometer splits). */
24
+ splitLengthMeters?: number;
25
+ /**
26
+ * A fix counts as "stopped" when its speed (or implied speed from the
27
+ * previous fix) stays below this, in meters per second. Default 0.5.
28
+ */
29
+ stopSpeedThresholdMps?: number;
30
+ };
31
+ export declare class TrackRecorder {
32
+ private readonly filterOptions;
33
+ private readonly splitLengthMeters;
34
+ private readonly stopSpeedThresholdMps;
35
+ private fixes;
36
+ private _distanceMeters;
37
+ private _movingMs;
38
+ private _elapsedMs;
39
+ private _splits;
40
+ private distanceAtSplitStart;
41
+ private timeAtSplitStart;
42
+ constructor(options?: RecorderOptions);
43
+ /**
44
+ * Offer a raw fix to the track. Returns true when the fix was accepted
45
+ * and recorded, false when a filter rule dropped it.
46
+ */
47
+ addFix(fix: TrackFix): boolean;
48
+ /** Accepted fixes, in order. */
49
+ get points(): TrackFix[];
50
+ get distanceMeters(): number;
51
+ /** Wall-clock time from first to last accepted fix, in milliseconds. */
52
+ get elapsedMs(): number;
53
+ /** Time actually spent moving (stops excluded), in milliseconds. */
54
+ get movingMs(): number;
55
+ /** Elapsed minus moving: time spent standing still, in milliseconds. */
56
+ get stoppedMs(): number;
57
+ /** True when the most recent movement looks like a stop. */
58
+ get isStopped(): boolean;
59
+ /** Completed splits so far. */
60
+ get splits(): Split[];
61
+ /** Average pace over the whole track, seconds per kilometer. */
62
+ get averagePaceSecondsPerKm(): number;
63
+ reset(): void;
64
+ }
65
+ //# sourceMappingURL=recorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../../../../src/geo/recorder.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,OAAO,EACb,MAAM,aAAU,CAAC;AAElB;;;;;;GAMG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,2EAA2E;IAC3E,cAAc,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAKF,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAE/C,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,gBAAgB,CAAK;gBAEjB,OAAO,GAAE,eAAoB;IAOzC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO;IA4C9B,gCAAgC;IAChC,IAAI,MAAM,IAAI,QAAQ,EAAE,CAEvB;IAED,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,wEAAwE;IACxE,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,oEAAoE;IACpE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,wEAAwE;IACxE,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,4DAA4D;IAC5D,IAAI,SAAS,IAAI,OAAO,CAQvB;IAED,+BAA+B;IAC/B,IAAI,MAAM,IAAI,KAAK,EAAE,CAEpB;IAED,gEAAgE;IAChE,IAAI,uBAAuB,IAAI,MAAM,CAKpC;IAED,KAAK,IAAI,IAAI;CASd"}
@@ -0,0 +1,44 @@
1
+ import NativeBackgroundGeolocation, { type GeolocationConfig, type GeolocationError, type LocationFix } from './NativeReactNativeBackgroundGeolocation.js';
2
+ export type { GeolocationConfig, GeolocationError, LocationFix };
3
+ export { haversineMeters, totalDistanceMeters, filterByAccuracy, durationSeconds, averagePaceMinPerKm, type Coordinate, type GeoFix, } from './location.js';
4
+ export { shouldAcceptFix, hasAcceptableAccuracy, isChronological, isFarEnough, DEFAULT_FILTER_OPTIONS, type FilterOptions, type FixLike, } from './geo/filter.js';
5
+ export { TrackRecorder, type TrackFix, type Split, type RecorderOptions, } from './geo/recorder.js';
6
+ type ListenerSubscription = ReturnType<typeof NativeBackgroundGeolocation.onLocation>;
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 declare function start(config?: GeolocationConfig): Promise<void>;
15
+ /** Stop tracking and release the native engine. */
16
+ export declare function stop(): Promise<void>;
17
+ /**
18
+ * One-shot position query: ask the OS where the device is right now,
19
+ * without starting continuous tracking.
20
+ */
21
+ export declare function getCurrentPosition(): Promise<LocationFix>;
22
+ /** Whether native tracking is currently running. */
23
+ export declare function isTracking(): Promise<boolean>;
24
+ /**
25
+ * Subscribe to fixes while tracking. Returns a subscription to remove.
26
+ *
27
+ * With codegen EventEmitter properties, the spec property itself is the
28
+ * subscribe function. Do NOT route this through NativeEventEmitter: its
29
+ * legacy addListener call throws inside the new-architecture TurboModule
30
+ * invocation layer and aborts the app (found the hard way, build 7).
31
+ */
32
+ export declare function addLocationListener(listener: (fix: LocationFix) => void): ListenerSubscription;
33
+ /** Subscribe to native engine errors. Returns a subscription to remove. */
34
+ export declare function addErrorListener(listener: (error: GeolocationError) => void): ListenerSubscription;
35
+ declare const _default: {
36
+ start: typeof start;
37
+ stop: typeof stop;
38
+ getCurrentPosition: typeof getCurrentPosition;
39
+ isTracking: typeof isTracking;
40
+ addLocationListener: typeof addLocationListener;
41
+ addErrorListener: typeof addErrorListener;
42
+ };
43
+ export default _default;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,EAAE,EAClC,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EACjB,MAAM,6CAA0C,CAAC;AAElD,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,CAAC;AAEjE,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,MAAM,GACZ,MAAM,eAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,WAAW,EACX,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,OAAO,GACb,MAAM,iBAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,eAAe,GACrB,MAAM,mBAAgB,CAAC;AAExB,KAAK,oBAAoB,GAAG,UAAU,CACpC,OAAO,2BAA2B,CAAC,UAAU,CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnE;AAED,mDAAmD;AACnD,wBAAgB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,WAAW,CAAC,CAEzD;AAED,oDAAoD;AACpD,wBAAgB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,GACnC,oBAAoB,CAEtB;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAC1C,oBAAoB,CAEtB;;;;;;;;;AAED,wBAOE"}
@@ -0,0 +1,35 @@
1
+ export interface GeoFix {
2
+ latitude: number;
3
+ longitude: number;
4
+ /** Unix epoch milliseconds, from the OS location timestamp. */
5
+ timestampMs: number;
6
+ /** Metres above sea level, when the OS reports it. */
7
+ altitude?: number;
8
+ /** Horizontal accuracy in metres, when the OS reports it. Lower is better. */
9
+ accuracy?: number;
10
+ /** Speed in m/s, when the OS reports it. */
11
+ speed?: number;
12
+ }
13
+ /** Anything with a latitude and a longitude: a fix, a waypoint, a pin. */
14
+ export type Coordinate = {
15
+ latitude: number;
16
+ longitude: number;
17
+ };
18
+ /** Great-circle distance between two coordinates, in metres. */
19
+ export declare function haversineMeters(a: Coordinate, b: Coordinate): number;
20
+ /** Sum of haversine distances between consecutive points, in metres. */
21
+ export declare function totalDistanceMeters(fixes: readonly Coordinate[]): number;
22
+ /**
23
+ * Drop fixes whose reported accuracy is worse than `maxAccuracyM`.
24
+ * Fixes with no accuracy reading are kept: the OS gave us no reason to
25
+ * distrust them. Default 50 m matches a typical running-track tolerance.
26
+ */
27
+ export declare function filterByAccuracy(fixes: readonly GeoFix[], maxAccuracyM?: number): GeoFix[];
28
+ /** Elapsed time between the first and last fix, in seconds. */
29
+ export declare function durationSeconds(fixes: readonly GeoFix[]): number;
30
+ /**
31
+ * Average pace in minutes per kilometre. Returns null when there is no
32
+ * usable distance or duration (avoids a divide-by-zero pace of Infinity).
33
+ */
34
+ export declare function averagePaceMinPerKm(fixes: readonly GeoFix[]): number | null;
35
+ //# sourceMappingURL=location.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../../src/location.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD,0EAA0E;AAC1E,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CASpE;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAUxE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,YAAY,SAAK,GAChB,MAAM,EAAE,CAIV;AAED,+DAA+D;AAC/D,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAOhE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAO3E"}