@maplibre/maplibre-react-native 11.0.0-alpha.12 → 11.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/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/components/camera/MLRNCameraComponentView.mm +5 -1
- 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/camera/Camera.js.map +1 -1
- package/lib/commonjs/components/camera/CameraNativeComponent.ts +6 -1
- 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/camera/Camera.js.map +1 -1
- package/lib/module/components/camera/CameraNativeComponent.ts +6 -1
- 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/camera/Camera.d.ts +1 -1
- package/lib/typescript/commonjs/src/components/camera/Camera.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/camera/CameraNativeComponent.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/camera/CameraNativeComponent.d.ts.map +1 -1
- 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/camera/Camera.d.ts +1 -1
- package/lib/typescript/module/src/components/camera/Camera.d.ts.map +1 -1
- package/lib/typescript/module/src/components/camera/CameraNativeComponent.d.ts +2 -1
- package/lib/typescript/module/src/components/camera/CameraNativeComponent.d.ts.map +1 -1
- 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/camera/Camera.tsx +2 -6
- package/src/components/camera/CameraNativeComponent.ts +6 -1
- 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
|
@@ -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
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.location.Location;
|
|
5
|
-
import android.os.Looper;
|
|
6
|
-
import android.util.Log;
|
|
7
|
-
|
|
8
|
-
import org.maplibre.android.location.engine.LocationEngine;
|
|
9
|
-
import org.maplibre.android.location.engine.LocationEngineCallback;
|
|
10
|
-
import org.maplibre.android.location.engine.LocationEngineRequest;
|
|
11
|
-
import org.maplibre.android.location.engine.LocationEngineResult;
|
|
12
|
-
import org.maplibre.android.location.permissions.PermissionsManager;
|
|
13
|
-
import org.maplibre.reactnative.location.engine.LocationEngineProvider;
|
|
14
|
-
|
|
15
|
-
import java.lang.ref.WeakReference;
|
|
16
|
-
import java.util.ArrayList;
|
|
17
|
-
import java.util.List;
|
|
18
|
-
|
|
19
|
-
@SuppressWarnings({"MissingPermission"})
|
|
20
|
-
public class LocationManager implements LocationEngineCallback<LocationEngineResult> {
|
|
21
|
-
static final long DEFAULT_FASTEST_INTERVAL_MILLIS = 1000;
|
|
22
|
-
static final long DEFAULT_INTERVAL_MILLIS = 1000;
|
|
23
|
-
|
|
24
|
-
public static final String LOG_TAG = "LocationManager";
|
|
25
|
-
|
|
26
|
-
private LocationEngine locationEngine;
|
|
27
|
-
private Context context;
|
|
28
|
-
private List<OnUserLocationChange> listeners = new ArrayList<>();
|
|
29
|
-
|
|
30
|
-
private float mMinDisplacement = 0;
|
|
31
|
-
private boolean isActive = false;
|
|
32
|
-
private Location lastLocation = null;
|
|
33
|
-
|
|
34
|
-
private LocationEngineRequest locationEngineRequest = null;
|
|
35
|
-
|
|
36
|
-
private static WeakReference<LocationManager> INSTANCE = null;
|
|
37
|
-
|
|
38
|
-
public static LocationManager getInstance(Context context) {
|
|
39
|
-
if (INSTANCE == null) {
|
|
40
|
-
INSTANCE = new WeakReference<>(new LocationManager(context));
|
|
41
|
-
}
|
|
42
|
-
return INSTANCE.get();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public interface OnUserLocationChange {
|
|
46
|
-
void onLocationChange(Location location);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private LocationManager(Context context) {
|
|
50
|
-
this.context = context;
|
|
51
|
-
this.buildEngineRequest();
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private void buildEngineRequest() {
|
|
56
|
-
locationEngine = new LocationEngineProvider().getLocationEngine(context);
|
|
57
|
-
|
|
58
|
-
locationEngineRequest = new LocationEngineRequest.Builder(DEFAULT_INTERVAL_MILLIS)
|
|
59
|
-
.setFastestInterval(DEFAULT_FASTEST_INTERVAL_MILLIS)
|
|
60
|
-
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
|
61
|
-
.setDisplacement(mMinDisplacement)
|
|
62
|
-
.build();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public void addLocationListener(OnUserLocationChange listener) {
|
|
66
|
-
if (!listeners.contains(listener)) {
|
|
67
|
-
listeners.add(listener);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public void removeLocationListener(OnUserLocationChange listener) {
|
|
72
|
-
if (listeners.contains(listener)) {
|
|
73
|
-
listeners.remove(listener);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public void setMinDisplacement(float minDisplacement) {
|
|
78
|
-
mMinDisplacement = minDisplacement;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public void enable() {
|
|
82
|
-
if (!PermissionsManager.areLocationPermissionsGranted(context)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// remove existing listeners
|
|
87
|
-
locationEngine.removeLocationUpdates(this);
|
|
88
|
-
|
|
89
|
-
// refresh location engine request with new values
|
|
90
|
-
this.buildEngineRequest();
|
|
91
|
-
|
|
92
|
-
// add new listeners
|
|
93
|
-
locationEngine.requestLocationUpdates(
|
|
94
|
-
locationEngineRequest,
|
|
95
|
-
this,
|
|
96
|
-
Looper.getMainLooper()
|
|
97
|
-
);
|
|
98
|
-
isActive = true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
public void disable() {
|
|
103
|
-
locationEngine.removeLocationUpdates(this);
|
|
104
|
-
isActive = false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public void dispose() {
|
|
108
|
-
if (locationEngine == null) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
disable();
|
|
112
|
-
locationEngine.removeLocationUpdates(this);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public boolean isActive() {
|
|
116
|
-
return locationEngine != null && this.isActive;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public Location getLastKnownLocation() {
|
|
120
|
-
if (locationEngine == null) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
return lastLocation;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
public void getLastKnownLocation(LocationEngineCallback<LocationEngineResult> callback) {
|
|
128
|
-
if (locationEngine == null) {
|
|
129
|
-
callback.onFailure(new Exception("LocationEngine not initialized"));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
locationEngine.getLastLocation(callback);
|
|
134
|
-
} catch (Exception exception) {
|
|
135
|
-
Log.w(LOG_TAG, exception);
|
|
136
|
-
callback.onFailure(exception);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public LocationEngine getEngine() {
|
|
141
|
-
return locationEngine;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public void onLocationChanged(Location location) {
|
|
145
|
-
lastLocation = location;
|
|
146
|
-
for (OnUserLocationChange listener : listeners) {
|
|
147
|
-
listener.onLocationChange(location);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@Override
|
|
152
|
-
public void onFailure(Exception exception) {
|
|
153
|
-
// TODO handle this.
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@Override
|
|
157
|
-
public void onSuccess(LocationEngineResult result) {
|
|
158
|
-
onLocationChanged(result.getLastLocation());
|
|
159
|
-
}
|
|
160
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location;
|
|
2
|
-
|
|
3
|
-
public class TrackUserLocationState {
|
|
4
|
-
// The map view not yet tracked the user location
|
|
5
|
-
public static final int POSSIBLE = 0;
|
|
6
|
-
|
|
7
|
-
// The map view has begun to move to the first user location
|
|
8
|
-
public static final int BEGAN = 1;
|
|
9
|
-
|
|
10
|
-
// The map views begins a significant transition
|
|
11
|
-
public static final int SIGNIFICANT_TRANSITION = 2;
|
|
12
|
-
|
|
13
|
-
// The map view has finished moving to the user location
|
|
14
|
-
public static final int CHANGED = 3;
|
|
15
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location;
|
|
2
|
-
|
|
3
|
-
import android.location.Location;
|
|
4
|
-
|
|
5
|
-
import org.maplibre.android.geometry.LatLng;
|
|
6
|
-
|
|
7
|
-
public class UserLocation {
|
|
8
|
-
private Location currentLocation;
|
|
9
|
-
private Location previousLocation;
|
|
10
|
-
|
|
11
|
-
private int userTrackingMode = TrackUserLocationMode.NONE;
|
|
12
|
-
|
|
13
|
-
public UserLocation() {
|
|
14
|
-
this(null);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public UserLocation(Location currentLocation) {
|
|
18
|
-
this.currentLocation = currentLocation;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public Location getCurrentLocation() {
|
|
22
|
-
return currentLocation;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public double getBearing() {
|
|
26
|
-
if (currentLocation == null) {
|
|
27
|
-
return 0.0;
|
|
28
|
-
}
|
|
29
|
-
return currentLocation.getBearing();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public LatLng getCoordinate() {
|
|
33
|
-
if (currentLocation == null) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public void setCurrentLocation(Location currentLocation) {
|
|
41
|
-
this.previousLocation = this.currentLocation;
|
|
42
|
-
this.currentLocation = currentLocation;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public void setTrackingMode(int userTrackingMode) {
|
|
46
|
-
this.userTrackingMode = userTrackingMode;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public int getTrackingMode() {
|
|
50
|
-
return userTrackingMode;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public float getDistance(Location location) {
|
|
54
|
-
if (currentLocation == null) {
|
|
55
|
-
return 0.0f;
|
|
56
|
-
}
|
|
57
|
-
return currentLocation.distanceTo(location);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location.engine;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
|
|
6
|
-
import org.maplibre.android.location.engine.LocationEngine;
|
|
7
|
-
import org.maplibre.android.location.engine.LocationEngineDefault;
|
|
8
|
-
|
|
9
|
-
public class DefaultLocationEngineProvider implements LocationEngineProvidable {
|
|
10
|
-
private static final String LOG_TAG = "DefaultLocationEngineProvider";
|
|
11
|
-
|
|
12
|
-
@Override
|
|
13
|
-
public LocationEngine getLocationEngine(Context context) {
|
|
14
|
-
LocationEngine locationEngine = LocationEngineDefault.INSTANCE.getDefaultLocationEngine(context.getApplicationContext());
|
|
15
|
-
Log.d(LOG_TAG, "DefaultLocationEngine will be used.");
|
|
16
|
-
return locationEngine;
|
|
17
|
-
}
|
|
18
|
-
}
|