@maplibre/maplibre-react-native 11.0.0-alpha.13 → 11.0.0-alpha.15

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 (95) hide show
  1. package/MapLibreReactNative.podspec +1 -1
  2. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +5 -5
  3. package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCamera.kt +27 -39
  4. package/android/src/main/java/org/maplibre/reactnative/events/constants/EventKeys.java +0 -4
  5. package/android/src/main/java/org/maplibre/reactnative/events/constants/EventTypes.java +0 -1
  6. package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.kt +165 -0
  7. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationMode.kt +0 -1
  8. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.kt +15 -0
  9. package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.kt +40 -0
  10. package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.kt +18 -0
  11. package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.kt +8 -0
  12. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +153 -0
  13. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +0 -5
  14. package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
  15. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.kt +131 -0
  16. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.kt +28 -0
  17. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
  18. package/ios/modules/location/MLRNLocation.h +0 -1
  19. package/ios/modules/location/MLRNLocation.m +3 -3
  20. package/ios/modules/location/MLRNLocationManager.h +1 -3
  21. package/ios/modules/location/MLRNLocationManager.m +1 -4
  22. package/ios/modules/location/MLRNLocationManagerDelegate.h +0 -2
  23. package/ios/modules/location/MLRNLocationModule.h +4 -4
  24. package/ios/modules/location/MLRNLocationModule.mm +56 -0
  25. package/ios/modules/mlrn/MLRNModule.m +0 -5
  26. package/ios/utils/MLRNEventTypes.h +0 -2
  27. package/ios/utils/MLRNEventTypes.m +0 -2
  28. package/lib/commonjs/components/user-location/UserLocation.js +3 -3
  29. package/lib/commonjs/components/user-location/UserLocation.js.map +1 -1
  30. package/lib/commonjs/index.js +2 -2
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/modules/location/LocationManager.js +46 -57
  33. package/lib/commonjs/modules/location/LocationManager.js.map +1 -1
  34. package/lib/commonjs/modules/location/NativeLocationModule.js +9 -0
  35. package/lib/commonjs/modules/location/NativeLocationModule.js.map +1 -0
  36. package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js +14 -0
  37. package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js.map +1 -0
  38. package/lib/module/components/user-location/UserLocation.js +3 -3
  39. package/lib/module/components/user-location/UserLocation.js.map +1 -1
  40. package/lib/module/index.js +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/modules/location/LocationManager.js +45 -57
  43. package/lib/module/modules/location/LocationManager.js.map +1 -1
  44. package/lib/module/modules/location/NativeLocationModule.js +5 -0
  45. package/lib/module/modules/location/NativeLocationModule.js.map +1 -0
  46. package/lib/module/modules/location/requestAndroidLocationPermissions.js +11 -0
  47. package/lib/module/modules/location/requestAndroidLocationPermissions.js.map +1 -0
  48. package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts +3 -3
  49. package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/src/index.d.ts +2 -2
  51. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +42 -22
  53. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +24 -0
  55. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
  57. package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
  58. package/lib/typescript/module/src/components/user-location/UserLocation.d.ts +3 -3
  59. package/lib/typescript/module/src/components/user-location/UserLocation.d.ts.map +1 -1
  60. package/lib/typescript/module/src/index.d.ts +2 -2
  61. package/lib/typescript/module/src/index.d.ts.map +1 -1
  62. package/lib/typescript/module/src/modules/location/LocationManager.d.ts +42 -22
  63. package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
  64. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +24 -0
  65. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -0
  66. package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
  67. package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
  68. package/package.json +5 -3
  69. package/src/components/user-location/UserLocation.tsx +9 -7
  70. package/src/index.ts +3 -2
  71. package/src/modules/location/LocationManager.ts +90 -97
  72. package/src/modules/location/NativeLocationModule.ts +31 -0
  73. package/src/modules/location/requestAndroidLocationPermissions.ts +8 -0
  74. package/android/src/main/java/org/maplibre/reactnative/events/LocationEvent.java +0 -100
  75. package/android/src/main/java/org/maplibre/reactnative/events/TrackUserLocationChangeEvent.kt +0 -24
  76. package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.java +0 -160
  77. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.java +0 -15
  78. package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.java +0 -59
  79. package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.java +0 -18
  80. package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.java +0 -9
  81. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.java +0 -158
  82. package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
  83. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.java +0 -151
  84. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.java +0 -24
  85. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
  86. package/ios/modules/location/MLRNLocationModule.m +0 -76
  87. package/lib/commonjs/requestAndroidLocationPermissions.js +0 -25
  88. package/lib/commonjs/requestAndroidLocationPermissions.js.map +0 -1
  89. package/lib/module/requestAndroidLocationPermissions.js +0 -21
  90. package/lib/module/requestAndroidLocationPermissions.js.map +0 -1
  91. package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts +0 -2
  92. package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts.map +0 -1
  93. package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts +0 -2
  94. package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts.map +0 -1
  95. package/src/requestAndroidLocationPermissions.ts +0 -29
@@ -0,0 +1,24 @@
1
+ import type { TurboModule, CodegenTypes } from "react-native";
2
+ type NativeGeolocationCoordinates = {
3
+ longitude: CodegenTypes.Double;
4
+ latitude: CodegenTypes.Double;
5
+ accuracy: CodegenTypes.Double;
6
+ altitude: CodegenTypes.Double;
7
+ altitudeAccuracy: CodegenTypes.Double | null;
8
+ heading: CodegenTypes.Double;
9
+ speed: CodegenTypes.Double;
10
+ };
11
+ type NativeGeolocationPosition = {
12
+ coords: NativeGeolocationCoordinates;
13
+ timestamp: number;
14
+ };
15
+ export interface Spec extends TurboModule {
16
+ start(): void;
17
+ stop(): void;
18
+ getCurrentPosition(): Promise<NativeGeolocationPosition>;
19
+ setMinDisplacement(minDisplacement: number): void;
20
+ readonly onUpdate: CodegenTypes.EventEmitter<NativeGeolocationPosition>;
21
+ }
22
+ declare const _default: Spec;
23
+ export default _default;
24
+ //# sourceMappingURL=NativeLocationModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLocationModule.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/location/NativeLocationModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG9D,KAAK,4BAA4B,GAAG;IAClC,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC;IAC9B,gBAAgB,EAAE,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC;CAC5B,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,4BAA4B,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,IAAI,IAAI,CAAC;IAEd,IAAI,IAAI,IAAI,CAAC;IAEb,kBAAkB,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEzD,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAElD,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAC;CACzE;;AAED,wBAA4E"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @deprected Use `LocationManager.requestAndroidPermissions` instead
3
+ */
4
+ export declare function requestAndroidLocationPermissions(): Promise<boolean>;
5
+ //# sourceMappingURL=requestAndroidLocationPermissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestAndroidLocationPermissions.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/location/requestAndroidLocationPermissions.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,OAAO,CAAC,CAE1E"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "11.0.0-alpha.13",
4
+ "version": "11.0.0-alpha.15",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true
@@ -127,10 +127,12 @@
127
127
  },
128
128
  "ios": {
129
129
  "componentProvider": {
130
- "MLRNMapView": "MLRNMapViewComponentView",
131
- "MLRNCamera": "MLRNCameraComponentView"
130
+ "MLRNCamera": "MLRNCameraComponentView",
131
+ "MLRNMapView": "MLRNMapViewComponentView"
132
132
  },
133
133
  "modulesProvider": {
134
+ "MLRNCameraModule": "MLRNCameraModule",
135
+ "MLRNLocationModule": "MLRNLocationModule",
134
136
  "MLRNMapViewModule": "MLRNMapViewModule"
135
137
  }
136
138
  }
@@ -11,7 +11,7 @@ import {
11
11
  import { NativeUserLocation } from "./NativeUserLocation";
12
12
  import { UserLocationPuck } from "./UserLocationPuck";
13
13
  import {
14
- type Location,
14
+ type GeolocationPosition,
15
15
  LocationManager,
16
16
  } from "../../modules/location/LocationManager";
17
17
  import { Annotation } from "../annotations/Annotation";
@@ -49,7 +49,7 @@ interface UserLocationProps {
49
49
  /**
50
50
  * Callback that is triggered on location update
51
51
  */
52
- onUpdate?: (location: Location) => void;
52
+ onUpdate?: (location: GeolocationPosition) => void;
53
53
  /**
54
54
  * Show or hide small arrow which indicates direction the device is pointing relative to north.
55
55
  */
@@ -86,7 +86,7 @@ export enum UserLocationRenderMode {
86
86
  export interface UserLocationRef {
87
87
  setLocationManager: (props: { running: boolean }) => Promise<void>;
88
88
  needsLocationManagerRunning: () => boolean;
89
- _onLocationUpdate: (location: Location | null) => void;
89
+ _onLocationUpdate: (location: GeolocationPosition | undefined) => void;
90
90
  }
91
91
 
92
92
  export const UserLocation = memo(
@@ -149,7 +149,7 @@ export const UserLocation = memo(
149
149
  return;
150
150
  }
151
151
 
152
- LocationManager.setMinDisplacement(minDisplacement ?? 0);
152
+ LocationManager.setMinDisplacement(minDisplacement);
153
153
  });
154
154
 
155
155
  return (): void => {
@@ -160,7 +160,7 @@ export const UserLocation = memo(
160
160
  }, []);
161
161
 
162
162
  useEffect(() => {
163
- LocationManager.setMinDisplacement(minDisplacement ?? 0);
163
+ LocationManager.setMinDisplacement(minDisplacement);
164
164
  }, [minDisplacement]);
165
165
 
166
166
  useEffect(() => {
@@ -183,7 +183,7 @@ export const UserLocation = memo(
183
183
 
184
184
  if (running) {
185
185
  LocationManager.addListener(_onLocationUpdate);
186
- const location = await LocationManager.getLastKnownLocation();
186
+ const location = await LocationManager.getCurrentPosition();
187
187
  _onLocationUpdate(location);
188
188
  } else {
189
189
  LocationManager.removeListener(_onLocationUpdate);
@@ -198,7 +198,9 @@ export const UserLocation = memo(
198
198
  );
199
199
  }
200
200
 
201
- function _onLocationUpdate(location: Location | null): void {
201
+ function _onLocationUpdate(
202
+ location: GeolocationPosition | undefined,
203
+ ): void {
202
204
  if (!_isMounted.current || !location) {
203
205
  return;
204
206
  }
package/src/index.ts CHANGED
@@ -28,7 +28,6 @@ export { PointAnnotation } from "./components/annotations/PointAnnotation";
28
28
  export type { PointAnnotationRef } from "./components/annotations/PointAnnotation";
29
29
  export { Annotation } from "./components/annotations/Annotation";
30
30
  export { Callout } from "./components/annotations/Callout";
31
- export { requestAndroidLocationPermissions } from "./requestAndroidLocationPermissions";
32
31
  export {
33
32
  UserLocation,
34
33
  UserLocationRenderMode,
@@ -52,8 +51,10 @@ export { MarkerView } from "./components/annotations/MarkerView";
52
51
 
53
52
  export {
54
53
  LocationManager,
55
- type Location,
54
+ type GeolocationPosition,
56
55
  } from "./modules/location/LocationManager";
56
+ export { requestAndroidLocationPermissions } from "./modules/location/requestAndroidLocationPermissions";
57
+
57
58
  export { OfflineManager } from "./modules/offline/OfflineManager";
58
59
  export type { OfflinePackError } from "./modules/offline/OfflineManager";
59
60
  export type { OfflinePackStatus } from "./modules/offline/OfflinePack";
@@ -1,160 +1,153 @@
1
1
  import {
2
- NativeModules,
3
- NativeEventEmitter,
4
- type EmitterSubscription,
2
+ type EventSubscription,
3
+ type Permission,
4
+ PermissionsAndroid,
5
5
  } from "react-native";
6
6
 
7
- const MLRNModule = NativeModules.MLRNModule;
8
- const MLRNLocationModule = NativeModules.MLRNLocationModule;
7
+ import NativeLocationModule from "./NativeLocationModule";
8
+ import { isAndroid } from "../../utils";
9
9
 
10
- export const LocationModuleEventEmitter = new NativeEventEmitter(
11
- MLRNLocationModule,
12
- );
13
-
14
- /*
15
- * Location sent by LocationManager
16
- */
17
- export interface Location {
18
- coords: Coordinates;
19
- timestamp?: number;
20
- }
21
-
22
- /*
23
- * Coordinates sent by LocationManager
24
- */
25
- interface Coordinates {
26
- /*
27
- * The heading (measured in degrees) relative to true north.
28
- * Heading is used to describe the direction the device is pointing to (the value of the compass).
29
- * Note that on Android this is incorrectly reporting the course value as mentioned in issue https://github.com/rnmapbox/maps/issues/1213
30
- * and will be corrected in a future update.
10
+ interface GeolocationCoordinates {
11
+ /**
12
+ * Longitude in degrees
31
13
  */
32
- heading?: number;
14
+ longitude: number;
33
15
 
34
- /*
35
- * The direction in which the device is traveling, measured in degrees and relative to due north.
36
- * The course refers to the direction the device is actually moving (not the same as heading).
16
+ /**
17
+ * Latitude in degrees
37
18
  */
38
- course?: number;
19
+ latitude: number;
39
20
 
40
- /*
41
- * The instantaneous speed of the device, measured in meters per second.
21
+ /**
22
+ * Accuracy for longitude/latitude in meters
42
23
  */
43
- speed?: number;
24
+ accuracy: number;
44
25
 
45
- /*
46
- * The latitude in degrees.
26
+ /**
27
+ * Altitude in meters
47
28
  */
48
- latitude: number;
29
+ altitude: number;
49
30
 
50
- /*
51
- * The longitude in degrees.
31
+ /**
32
+ * Accuracy for altitude in meters
52
33
  */
53
- longitude: number;
34
+ altitudeAccuracy: number | null;
54
35
 
55
- /*
56
- * The radius of uncertainty for the location, measured in meters.
36
+ /**
37
+ * Direction in which the device is traveling in degrees, relative to north
57
38
  */
58
- accuracy?: number;
39
+ heading: number;
59
40
 
60
- /*
61
- * The altitude, measured in meters.
41
+ /**
42
+ * Instantaneous speed of the device in meters per second
62
43
  */
63
- altitude?: number;
44
+ speed: number;
45
+ }
46
+
47
+ export interface GeolocationPosition {
48
+ coords: GeolocationCoordinates;
49
+
50
+ timestamp: number;
64
51
  }
65
52
 
66
53
  class LocationManager {
67
- _listeners: ((location: Location) => void)[];
68
- _lastKnownLocation: Location | null;
69
- _isListening: boolean;
70
- subscription: EmitterSubscription | null;
54
+ private listeners: ((location: GeolocationPosition) => void)[] = [];
55
+ private currentPosition: GeolocationPosition | undefined = undefined;
56
+ private isListening: boolean = false;
57
+
58
+ private subscription: EventSubscription | undefined = undefined;
71
59
 
72
60
  constructor() {
73
- this._listeners = [];
74
- this._lastKnownLocation = null;
75
- this._isListening = false;
76
- this.onUpdate = this.onUpdate.bind(this);
77
- this.subscription = null;
61
+ this.handleUpdate = this.handleUpdate.bind(this);
78
62
  }
79
63
 
80
- async getLastKnownLocation(): Promise<Location | null> {
81
- if (!this._lastKnownLocation) {
82
- let lastKnownLocation;
83
-
84
- // as location can be brittle it might happen,
85
- // that we get an exception from native land
86
- // let's silently catch it and simply log out
87
- // instead of throwing an exception
88
- try {
89
- lastKnownLocation = await MLRNLocationModule.getLastKnownLocation();
90
- } catch (error) {
91
- console.log("LocationManager Error: ", error);
92
- }
64
+ async getCurrentPosition(): Promise<GeolocationPosition | undefined> {
65
+ let currentPosition;
93
66
 
94
- if (!this._lastKnownLocation && lastKnownLocation) {
95
- this._lastKnownLocation = lastKnownLocation;
96
- }
67
+ try {
68
+ currentPosition = await NativeLocationModule.getCurrentPosition();
69
+ } catch (error) {
70
+ console.log("LocationManager [error]: ", error);
97
71
  }
98
72
 
99
- return this._lastKnownLocation;
73
+ this.currentPosition = currentPosition;
74
+
75
+ return this.currentPosition;
100
76
  }
101
77
 
102
- addListener(listener: (location: Location) => void): void {
103
- if (!this._isListening) {
78
+ addListener(newListener: (location: GeolocationPosition) => void): void {
79
+ if (!this.isListening) {
104
80
  this.start();
105
81
  }
106
- if (!this._listeners.includes(listener)) {
107
- this._listeners.push(listener);
108
82
 
109
- if (this._lastKnownLocation) {
110
- listener(this._lastKnownLocation);
83
+ if (!this.listeners.includes(newListener)) {
84
+ this.listeners.push(newListener);
85
+
86
+ if (this.currentPosition) {
87
+ newListener(this.currentPosition);
111
88
  }
112
89
  }
113
90
  }
114
91
 
115
- removeListener(listener: (location: Location) => void): void {
116
- this._listeners = this._listeners.filter((l) => l !== listener);
117
- if (this._listeners.length === 0) {
92
+ removeListener(oldListener: (location: GeolocationPosition) => void): void {
93
+ this.listeners = this.listeners.filter(
94
+ (listener) => listener !== oldListener,
95
+ );
96
+
97
+ if (this.listeners.length === 0) {
118
98
  this.stop();
119
99
  }
120
100
  }
121
101
 
122
102
  removeAllListeners(): void {
123
- this._listeners = [];
103
+ this.listeners = [];
104
+
124
105
  this.stop();
125
106
  }
126
107
 
127
- start(displacement = 0): void {
128
- if (!this._isListening) {
129
- MLRNLocationModule.start(displacement);
108
+ start(): void {
109
+ if (!this.isListening) {
110
+ NativeLocationModule.start();
130
111
 
131
- this.subscription = LocationModuleEventEmitter.addListener(
132
- MLRNModule.LocationCallbackName.Update,
133
- this.onUpdate,
134
- );
112
+ this.subscription = NativeLocationModule.onUpdate(this.handleUpdate);
135
113
 
136
- this._isListening = true;
114
+ this.isListening = true;
137
115
  }
138
116
  }
139
117
 
140
118
  stop(): void {
141
- MLRNLocationModule.stop();
119
+ NativeLocationModule.stop();
142
120
 
143
- if (this._isListening) {
121
+ if (this.isListening) {
144
122
  this.subscription?.remove();
145
123
  }
146
124
 
147
- this._isListening = false;
125
+ this.isListening = false;
148
126
  }
149
127
 
150
128
  setMinDisplacement(minDisplacement: number): void {
151
- MLRNLocationModule.setMinDisplacement(minDisplacement);
129
+ NativeLocationModule.setMinDisplacement(minDisplacement);
152
130
  }
153
131
 
154
- onUpdate(location: Location): void {
155
- this._lastKnownLocation = location;
132
+ private handleUpdate(location: GeolocationPosition): void {
133
+ this.currentPosition = location;
134
+
135
+ this.listeners.forEach((listener) => listener(location));
136
+ }
137
+
138
+ async requestAndroidPermissions(): Promise<boolean> {
139
+ if (isAndroid()) {
140
+ const res = await PermissionsAndroid.requestMultiple([
141
+ PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,
142
+ PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,
143
+ ]);
144
+
145
+ return Object.values(res).every(
146
+ (permission) => permission === PermissionsAndroid.RESULTS.GRANTED,
147
+ );
148
+ }
156
149
 
157
- this._listeners.forEach((l) => l(location));
150
+ throw new Error("This method should only be called on Android");
158
151
  }
159
152
  }
160
153
 
@@ -0,0 +1,31 @@
1
+ import type { TurboModule, CodegenTypes } from "react-native";
2
+ import { TurboModuleRegistry } from "react-native";
3
+
4
+ type NativeGeolocationCoordinates = {
5
+ longitude: CodegenTypes.Double;
6
+ latitude: CodegenTypes.Double;
7
+ accuracy: CodegenTypes.Double;
8
+ altitude: CodegenTypes.Double;
9
+ altitudeAccuracy: CodegenTypes.Double | null;
10
+ heading: CodegenTypes.Double;
11
+ speed: CodegenTypes.Double;
12
+ };
13
+
14
+ type NativeGeolocationPosition = {
15
+ coords: NativeGeolocationCoordinates;
16
+ timestamp: number;
17
+ };
18
+
19
+ export interface Spec extends TurboModule {
20
+ start(): void;
21
+
22
+ stop(): void;
23
+
24
+ getCurrentPosition(): Promise<NativeGeolocationPosition>;
25
+
26
+ setMinDisplacement(minDisplacement: number): void;
27
+
28
+ readonly onUpdate: CodegenTypes.EventEmitter<NativeGeolocationPosition>;
29
+ }
30
+
31
+ export default TurboModuleRegistry.getEnforcing<Spec>("MLRNLocationModule");
@@ -0,0 +1,8 @@
1
+ import { LocationManager } from "./LocationManager";
2
+
3
+ /**
4
+ * @deprected Use `LocationManager.requestAndroidPermissions` instead
5
+ */
6
+ export async function requestAndroidLocationPermissions(): Promise<boolean> {
7
+ return LocationManager.requestAndroidPermissions();
8
+ }
@@ -1,100 +0,0 @@
1
- package org.maplibre.reactnative.events;
2
-
3
- import android.location.Location;
4
- import androidx.annotation.NonNull;
5
-
6
- import com.facebook.react.bridge.Arguments;
7
- import com.facebook.react.bridge.WritableMap;
8
- import com.facebook.react.bridge.WritableNativeMap;
9
- import org.maplibre.reactnative.components.mapview.MLRNMapView;
10
- import org.maplibre.reactnative.events.constants.EventKeys;
11
- import org.maplibre.reactnative.events.constants.EventTypes;
12
-
13
- import java.util.UUID;
14
-
15
- public class LocationEvent implements IEvent {
16
- private UUID uuid;
17
- private MLRNMapView mapView;
18
- private Location location;
19
-
20
- public LocationEvent(@NonNull Location location, MLRNMapView mapView) {
21
- this.mapView = mapView;
22
- this.location = location;
23
- this.uuid = UUID.randomUUID();
24
- }
25
-
26
- public LocationEvent(Location location) {
27
- this(location, null);
28
- }
29
-
30
- @Override
31
- public int getID() {
32
- if (mapView != null) {
33
- return mapView.getId();
34
- }
35
- return -1;
36
- }
37
-
38
- public UUID getUUID() {
39
- return uuid;
40
- }
41
-
42
- @Override
43
- public String getKey() {
44
- return EventKeys.USER_LOCATION_UPDATE;
45
- }
46
-
47
- @Override
48
- public String getType() {
49
- return EventTypes.USER_LOCATION_UPDATED;
50
- }
51
-
52
- @Override
53
- public long getTimestamp() {
54
- return System.currentTimeMillis();
55
- }
56
-
57
- @Override
58
- public boolean equals(IEvent event) {
59
- LocationEvent other = (LocationEvent) event;
60
- return getUUID().equals(other.getUUID());
61
- }
62
-
63
- public boolean equals(LocationEvent event) {
64
- return uuid.equals(event.getUUID());
65
- }
66
-
67
- @Override
68
- public WritableMap getPayload() {
69
- WritableMap positionProperties = new WritableNativeMap();
70
- WritableMap coords = new WritableNativeMap();
71
-
72
- coords.putDouble("longitude", location.getLongitude());
73
- coords.putDouble("latitude", location.getLatitude());
74
- coords.putDouble("altitude", location.getAltitude());
75
- coords.putDouble("accuracy", location.getAccuracy());
76
- // A better solution will be to pull the heading from the compass engine,
77
- // unfortunately the api is not publicly available in the mapbox sdk
78
- coords.putDouble("heading", location.getBearing());
79
- coords.putDouble("course", location.getBearing());
80
- coords.putDouble("speed", location.getSpeed());
81
-
82
- positionProperties.putMap("coords", coords);
83
- positionProperties.putDouble("timestamp", location.getTime());
84
-
85
- return positionProperties;
86
- }
87
-
88
- @Override
89
- public WritableMap toJSON() {
90
- WritableMap map = Arguments.createMap();
91
- map.putString("type", getType());
92
- map.putMap("payload", getPayload());
93
- return map;
94
- }
95
-
96
- @Override
97
- public boolean canCoalesce() {
98
- return true;
99
- }
100
- }
@@ -1,24 +0,0 @@
1
- package org.maplibre.reactnative.events
2
-
3
- import android.view.View
4
- import com.facebook.react.bridge.Arguments
5
- import com.facebook.react.bridge.WritableMap
6
- import com.facebook.react.uimanager.events.Event
7
- import org.maplibre.reactnative.events.constants.EventKeys
8
- import org.maplibre.reactnative.events.constants.EventTypes
9
- import org.maplibre.reactnative.location.TrackUserLocationMode
10
-
11
- class TrackUserLocationChangeEvent(
12
- surfaceId: Int,
13
- viewId: Int,
14
- private val trackUserLocationMode: Int
15
- ) :
16
- Event<TrackUserLocationChangeEvent>(surfaceId, viewId) {
17
- override fun getEventName() = "onTrackUserLocationChange"
18
-
19
- override fun getEventData(): WritableMap? {
20
- return Arguments.createMap().apply {
21
- putString("trackUserLocation", TrackUserLocationMode.toString(trackUserLocationMode))
22
- }
23
- }
24
- }