@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.
- package/MapLibreReactNative.podspec +1 -1
- package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +5 -5
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCamera.kt +27 -39
- package/android/src/main/java/org/maplibre/reactnative/events/constants/EventKeys.java +0 -4
- package/android/src/main/java/org/maplibre/reactnative/events/constants/EventTypes.java +0 -1
- package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.kt +165 -0
- package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationMode.kt +0 -1
- package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.kt +15 -0
- package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.kt +40 -0
- package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.kt +18 -0
- package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.kt +8 -0
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +153 -0
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +0 -5
- package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.kt +131 -0
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.kt +28 -0
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
- package/ios/modules/location/MLRNLocation.h +0 -1
- package/ios/modules/location/MLRNLocation.m +3 -3
- package/ios/modules/location/MLRNLocationManager.h +1 -3
- package/ios/modules/location/MLRNLocationManager.m +1 -4
- package/ios/modules/location/MLRNLocationManagerDelegate.h +0 -2
- package/ios/modules/location/MLRNLocationModule.h +4 -4
- package/ios/modules/location/MLRNLocationModule.mm +56 -0
- package/ios/modules/mlrn/MLRNModule.m +0 -5
- package/ios/utils/MLRNEventTypes.h +0 -2
- package/ios/utils/MLRNEventTypes.m +0 -2
- package/lib/commonjs/components/user-location/UserLocation.js +3 -3
- package/lib/commonjs/components/user-location/UserLocation.js.map +1 -1
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/location/LocationManager.js +46 -57
- package/lib/commonjs/modules/location/LocationManager.js.map +1 -1
- package/lib/commonjs/modules/location/NativeLocationModule.js +9 -0
- package/lib/commonjs/modules/location/NativeLocationModule.js.map +1 -0
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js +14 -0
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js.map +1 -0
- package/lib/module/components/user-location/UserLocation.js +3 -3
- package/lib/module/components/user-location/UserLocation.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/location/LocationManager.js +45 -57
- package/lib/module/modules/location/LocationManager.js.map +1 -1
- package/lib/module/modules/location/NativeLocationModule.js +5 -0
- package/lib/module/modules/location/NativeLocationModule.js.map +1 -0
- package/lib/module/modules/location/requestAndroidLocationPermissions.js +11 -0
- package/lib/module/modules/location/requestAndroidLocationPermissions.js.map +1 -0
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts +3 -3
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +42 -22
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +24 -0
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts +3 -3
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +2 -2
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts +42 -22
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +24 -0
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
- package/package.json +5 -3
- package/src/components/user-location/UserLocation.tsx +9 -7
- package/src/index.ts +3 -2
- package/src/modules/location/LocationManager.ts +90 -97
- package/src/modules/location/NativeLocationModule.ts +31 -0
- package/src/modules/location/requestAndroidLocationPermissions.ts +8 -0
- package/android/src/main/java/org/maplibre/reactnative/events/LocationEvent.java +0 -100
- package/android/src/main/java/org/maplibre/reactnative/events/TrackUserLocationChangeEvent.kt +0 -24
- package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.java +0 -160
- package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.java +0 -15
- package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.java +0 -59
- package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.java +0 -18
- package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.java +0 -9
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.java +0 -158
- package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.java +0 -151
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.java +0 -24
- package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
- package/ios/modules/location/MLRNLocationModule.m +0 -76
- package/lib/commonjs/requestAndroidLocationPermissions.js +0 -25
- package/lib/commonjs/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/module/requestAndroidLocationPermissions.js +0 -21
- package/lib/module/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts +0 -2
- package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts.map +0 -1
- package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts +0 -2
- package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts.map +0 -1
- 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 @@
|
|
|
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.
|
|
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
|
-
"
|
|
131
|
-
"
|
|
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
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
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.
|
|
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(
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type EventSubscription,
|
|
3
|
+
type Permission,
|
|
4
|
+
PermissionsAndroid,
|
|
5
5
|
} from "react-native";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import NativeLocationModule from "./NativeLocationModule";
|
|
8
|
+
import { isAndroid } from "../../utils";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
+
longitude: number;
|
|
33
15
|
|
|
34
|
-
|
|
35
|
-
*
|
|
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
|
-
|
|
19
|
+
latitude: number;
|
|
39
20
|
|
|
40
|
-
|
|
41
|
-
*
|
|
21
|
+
/**
|
|
22
|
+
* Accuracy for longitude/latitude in meters
|
|
42
23
|
*/
|
|
43
|
-
|
|
24
|
+
accuracy: number;
|
|
44
25
|
|
|
45
|
-
|
|
46
|
-
*
|
|
26
|
+
/**
|
|
27
|
+
* Altitude in meters
|
|
47
28
|
*/
|
|
48
|
-
|
|
29
|
+
altitude: number;
|
|
49
30
|
|
|
50
|
-
|
|
51
|
-
*
|
|
31
|
+
/**
|
|
32
|
+
* Accuracy for altitude in meters
|
|
52
33
|
*/
|
|
53
|
-
|
|
34
|
+
altitudeAccuracy: number | null;
|
|
54
35
|
|
|
55
|
-
|
|
56
|
-
*
|
|
36
|
+
/**
|
|
37
|
+
* Direction in which the device is traveling in degrees, relative to north
|
|
57
38
|
*/
|
|
58
|
-
|
|
39
|
+
heading: number;
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
*
|
|
41
|
+
/**
|
|
42
|
+
* Instantaneous speed of the device in meters per second
|
|
62
43
|
*/
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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.
|
|
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
|
|
81
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
67
|
+
try {
|
|
68
|
+
currentPosition = await NativeLocationModule.getCurrentPosition();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log("LocationManager [error]: ", error);
|
|
97
71
|
}
|
|
98
72
|
|
|
99
|
-
|
|
73
|
+
this.currentPosition = currentPosition;
|
|
74
|
+
|
|
75
|
+
return this.currentPosition;
|
|
100
76
|
}
|
|
101
77
|
|
|
102
|
-
addListener(
|
|
103
|
-
if (!this.
|
|
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
|
-
|
|
110
|
-
|
|
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(
|
|
116
|
-
this.
|
|
117
|
-
|
|
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.
|
|
103
|
+
this.listeners = [];
|
|
104
|
+
|
|
124
105
|
this.stop();
|
|
125
106
|
}
|
|
126
107
|
|
|
127
|
-
start(
|
|
128
|
-
if (!this.
|
|
129
|
-
|
|
108
|
+
start(): void {
|
|
109
|
+
if (!this.isListening) {
|
|
110
|
+
NativeLocationModule.start();
|
|
130
111
|
|
|
131
|
-
this.subscription =
|
|
132
|
-
MLRNModule.LocationCallbackName.Update,
|
|
133
|
-
this.onUpdate,
|
|
134
|
-
);
|
|
112
|
+
this.subscription = NativeLocationModule.onUpdate(this.handleUpdate);
|
|
135
113
|
|
|
136
|
-
this.
|
|
114
|
+
this.isListening = true;
|
|
137
115
|
}
|
|
138
116
|
}
|
|
139
117
|
|
|
140
118
|
stop(): void {
|
|
141
|
-
|
|
119
|
+
NativeLocationModule.stop();
|
|
142
120
|
|
|
143
|
-
if (this.
|
|
121
|
+
if (this.isListening) {
|
|
144
122
|
this.subscription?.remove();
|
|
145
123
|
}
|
|
146
124
|
|
|
147
|
-
this.
|
|
125
|
+
this.isListening = false;
|
|
148
126
|
}
|
|
149
127
|
|
|
150
128
|
setMinDisplacement(minDisplacement: number): void {
|
|
151
|
-
|
|
129
|
+
NativeLocationModule.setMinDisplacement(minDisplacement);
|
|
152
130
|
}
|
|
153
131
|
|
|
154
|
-
|
|
155
|
-
this.
|
|
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
|
-
|
|
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
|
-
}
|
package/android/src/main/java/org/maplibre/reactnative/events/TrackUserLocationChangeEvent.kt
DELETED
|
@@ -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
|
-
}
|