@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,158 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.modules;
|
|
2
|
-
|
|
3
|
-
import android.location.Location;
|
|
4
|
-
import androidx.annotation.NonNull;
|
|
5
|
-
|
|
6
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
7
|
-
import com.facebook.react.bridge.Promise;
|
|
8
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
10
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
12
|
-
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
|
|
13
|
-
import org.maplibre.android.location.engine.LocationEngineCallback;
|
|
14
|
-
import org.maplibre.android.location.engine.LocationEngineResult;
|
|
15
|
-
import org.maplibre.reactnative.events.EventEmitter;
|
|
16
|
-
import org.maplibre.reactnative.events.LocationEvent;
|
|
17
|
-
import org.maplibre.reactnative.location.LocationManager;
|
|
18
|
-
|
|
19
|
-
@ReactModule(name = MLRNLocationModule.REACT_CLASS)
|
|
20
|
-
public class MLRNLocationModule extends ReactContextBaseJavaModule {
|
|
21
|
-
public static final String REACT_CLASS = "MLRNLocationModule";
|
|
22
|
-
public static final String LOCATION_UPDATE = "MapboxUserLocationUpdate";
|
|
23
|
-
|
|
24
|
-
private boolean isEnabled;
|
|
25
|
-
private float mMinDisplacement;
|
|
26
|
-
private boolean isPaused;
|
|
27
|
-
|
|
28
|
-
private LocationManager locationManager;
|
|
29
|
-
|
|
30
|
-
private LifecycleEventListener lifecycleEventListener = new LifecycleEventListener() {
|
|
31
|
-
@Override
|
|
32
|
-
public void onHostResume() {
|
|
33
|
-
if (isEnabled) {
|
|
34
|
-
startLocationManager();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@Override
|
|
39
|
-
public void onHostPause() {
|
|
40
|
-
pauseLocationManager();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Override
|
|
44
|
-
public void onHostDestroy() {
|
|
45
|
-
stopLocationManager();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
private LocationManager.OnUserLocationChange onUserLocationChangeCallback = new LocationManager.OnUserLocationChange() {
|
|
50
|
-
@Override
|
|
51
|
-
public void onLocationChange(Location location) {
|
|
52
|
-
LocationEvent locationEvent = new LocationEvent(location);
|
|
53
|
-
|
|
54
|
-
RCTNativeAppEventEmitter emitter = EventEmitter.getModuleEmitter(getReactApplicationContext());
|
|
55
|
-
if (emitter != null) {
|
|
56
|
-
emitter.emit(LOCATION_UPDATE, locationEvent.getPayload());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
public MLRNLocationModule(ReactApplicationContext reactContext) {
|
|
62
|
-
super(reactContext);
|
|
63
|
-
locationManager = LocationManager.getInstance(reactContext);
|
|
64
|
-
reactContext.addLifecycleEventListener(lifecycleEventListener);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@Override
|
|
68
|
-
public String getName() {
|
|
69
|
-
return REACT_CLASS;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@ReactMethod
|
|
74
|
-
public void start(float minDisplacement) {
|
|
75
|
-
isEnabled = true;
|
|
76
|
-
mMinDisplacement = minDisplacement;
|
|
77
|
-
startLocationManager();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@ReactMethod
|
|
81
|
-
public void setMinDisplacement(float minDisplacement) {
|
|
82
|
-
if (mMinDisplacement == minDisplacement) return;
|
|
83
|
-
mMinDisplacement = minDisplacement;
|
|
84
|
-
if (isEnabled) {
|
|
85
|
-
|
|
86
|
-
// set minimal displacement in the manager
|
|
87
|
-
locationManager.setMinDisplacement(mMinDisplacement);
|
|
88
|
-
|
|
89
|
-
// refresh values in location engine request
|
|
90
|
-
locationManager.enable();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@ReactMethod
|
|
95
|
-
public void stop() {
|
|
96
|
-
stopLocationManager();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@ReactMethod
|
|
100
|
-
public void pause() {
|
|
101
|
-
pauseLocationManager();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@ReactMethod
|
|
105
|
-
public void getLastKnownLocation(final Promise promise) {
|
|
106
|
-
locationManager.getLastKnownLocation(
|
|
107
|
-
new LocationEngineCallback<LocationEngineResult>() {
|
|
108
|
-
public void onSuccess(LocationEngineResult result) {
|
|
109
|
-
Location location = result.getLastLocation();
|
|
110
|
-
if (result.getLastLocation() != null) {
|
|
111
|
-
LocationEvent locationEvent = new LocationEvent(location);
|
|
112
|
-
promise.resolve(locationEvent.getPayload());
|
|
113
|
-
} else {
|
|
114
|
-
promise.resolve(null);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
public void onFailure(@NonNull Exception exception) {
|
|
118
|
-
promise.reject(exception);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@ReactMethod
|
|
125
|
-
public void addListener(String eventName) {
|
|
126
|
-
// Set up any upstream listeners or background tasks as necessary
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
@ReactMethod
|
|
130
|
-
public void removeListeners(Integer count) {
|
|
131
|
-
// Remove upstream listeners, stop unnecessary background tasks
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private void startLocationManager() {
|
|
135
|
-
locationManager.addLocationListener(onUserLocationChangeCallback);
|
|
136
|
-
locationManager.setMinDisplacement(mMinDisplacement);
|
|
137
|
-
locationManager.enable();
|
|
138
|
-
isPaused = false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private void pauseLocationManager() {
|
|
142
|
-
if (isPaused) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
locationManager.disable();
|
|
146
|
-
isPaused = true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private void stopLocationManager() {
|
|
150
|
-
if (!isEnabled) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
locationManager.removeLocationListener(onUserLocationChangeCallback);
|
|
154
|
-
locationManager.dispose();
|
|
155
|
-
isEnabled = false;
|
|
156
|
-
isPaused = false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location.engine;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import org.maplibre.android.location.engine.LocationEngine;
|
|
6
|
-
|
|
7
|
-
public class LocationEngineProvider implements LocationEngineProvidable {
|
|
8
|
-
@Override
|
|
9
|
-
public LocationEngine getLocationEngine(Context context) {
|
|
10
|
-
return new DefaultLocationEngineProvider().getLocationEngine(context);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location.engine;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.app.PendingIntent;
|
|
5
|
-
import android.content.Context;
|
|
6
|
-
import android.location.Location;
|
|
7
|
-
import android.os.Looper;
|
|
8
|
-
|
|
9
|
-
import androidx.annotation.NonNull;
|
|
10
|
-
import androidx.annotation.Nullable;
|
|
11
|
-
import androidx.annotation.VisibleForTesting;
|
|
12
|
-
|
|
13
|
-
import com.google.android.gms.location.FusedLocationProviderClient;
|
|
14
|
-
import com.google.android.gms.location.LocationCallback;
|
|
15
|
-
import com.google.android.gms.location.LocationRequest;
|
|
16
|
-
import com.google.android.gms.location.LocationResult;
|
|
17
|
-
import com.google.android.gms.location.LocationServices;
|
|
18
|
-
import com.google.android.gms.location.Priority;
|
|
19
|
-
import com.google.android.gms.tasks.OnFailureListener;
|
|
20
|
-
import com.google.android.gms.tasks.OnSuccessListener;
|
|
21
|
-
|
|
22
|
-
import org.maplibre.android.location.engine.LocationEngineCallback;
|
|
23
|
-
import org.maplibre.android.location.engine.LocationEngineImpl;
|
|
24
|
-
import org.maplibre.android.location.engine.LocationEngineRequest;
|
|
25
|
-
import org.maplibre.android.location.engine.LocationEngineResult;
|
|
26
|
-
|
|
27
|
-
import java.util.Collections;
|
|
28
|
-
import java.util.List;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Wraps implementation of Fused Location Provider
|
|
32
|
-
*/
|
|
33
|
-
public class GoogleLocationEngineImpl implements LocationEngineImpl<LocationCallback> {
|
|
34
|
-
private final FusedLocationProviderClient fusedLocationProviderClient;
|
|
35
|
-
|
|
36
|
-
@VisibleForTesting
|
|
37
|
-
GoogleLocationEngineImpl(FusedLocationProviderClient fusedLocationProviderClient) {
|
|
38
|
-
this.fusedLocationProviderClient = fusedLocationProviderClient;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public GoogleLocationEngineImpl(@NonNull Context context) {
|
|
42
|
-
this.fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@NonNull
|
|
46
|
-
@Override
|
|
47
|
-
public LocationCallback createListener(LocationEngineCallback<LocationEngineResult> callback) {
|
|
48
|
-
return new GoogleLocationEngineCallbackTransport(callback);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@SuppressLint("MissingPermission")
|
|
52
|
-
@Override
|
|
53
|
-
public void getLastLocation(@NonNull LocationEngineCallback<LocationEngineResult> callback)
|
|
54
|
-
throws SecurityException {
|
|
55
|
-
GoogleLastLocationEngineCallbackTransport transport =
|
|
56
|
-
new GoogleLastLocationEngineCallbackTransport(callback);
|
|
57
|
-
fusedLocationProviderClient.getLastLocation().addOnSuccessListener(transport).addOnFailureListener(transport);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@SuppressLint("MissingPermission")
|
|
61
|
-
@Override
|
|
62
|
-
public void requestLocationUpdates(@NonNull LocationEngineRequest request,
|
|
63
|
-
@NonNull LocationCallback listener,
|
|
64
|
-
@Nullable Looper looper) throws SecurityException {
|
|
65
|
-
fusedLocationProviderClient.requestLocationUpdates(toGMSLocationRequest(request), listener, looper);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@SuppressLint("MissingPermission")
|
|
69
|
-
@Override
|
|
70
|
-
public void requestLocationUpdates(@NonNull LocationEngineRequest request,
|
|
71
|
-
@NonNull PendingIntent pendingIntent) throws SecurityException {
|
|
72
|
-
fusedLocationProviderClient.requestLocationUpdates(toGMSLocationRequest(request), pendingIntent);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Override
|
|
76
|
-
public void removeLocationUpdates(@NonNull LocationCallback listener) {
|
|
77
|
-
if (listener != null) {
|
|
78
|
-
fusedLocationProviderClient.removeLocationUpdates(listener);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@Override
|
|
83
|
-
public void removeLocationUpdates(PendingIntent pendingIntent) {
|
|
84
|
-
if (pendingIntent != null) {
|
|
85
|
-
fusedLocationProviderClient.removeLocationUpdates(pendingIntent);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private static LocationRequest toGMSLocationRequest(LocationEngineRequest request) {
|
|
90
|
-
LocationRequest.Builder builder = new LocationRequest.Builder(request.getInterval());
|
|
91
|
-
builder.setMinUpdateIntervalMillis(request.getFastestInterval());
|
|
92
|
-
builder.setMinUpdateDistanceMeters(request.getDisplacement());
|
|
93
|
-
builder.setMaxUpdateDelayMillis(request.getMaxWaitTime());
|
|
94
|
-
builder.setPriority(toGMSLocationPriority(request.getPriority()));
|
|
95
|
-
return builder.build();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private static int toGMSLocationPriority(int enginePriority) {
|
|
99
|
-
switch (enginePriority) {
|
|
100
|
-
case LocationEngineRequest.PRIORITY_HIGH_ACCURACY:
|
|
101
|
-
return Priority.PRIORITY_HIGH_ACCURACY;
|
|
102
|
-
case LocationEngineRequest.PRIORITY_BALANCED_POWER_ACCURACY:
|
|
103
|
-
return Priority.PRIORITY_BALANCED_POWER_ACCURACY;
|
|
104
|
-
case LocationEngineRequest.PRIORITY_LOW_POWER:
|
|
105
|
-
return Priority.PRIORITY_LOW_POWER;
|
|
106
|
-
case LocationEngineRequest.PRIORITY_NO_POWER:
|
|
107
|
-
default:
|
|
108
|
-
return Priority.PRIORITY_PASSIVE;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private static final class GoogleLocationEngineCallbackTransport extends LocationCallback {
|
|
113
|
-
private final LocationEngineCallback<LocationEngineResult> callback;
|
|
114
|
-
|
|
115
|
-
GoogleLocationEngineCallbackTransport(LocationEngineCallback<LocationEngineResult> callback) {
|
|
116
|
-
this.callback = callback;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Override
|
|
120
|
-
public void onLocationResult(LocationResult locationResult) {
|
|
121
|
-
super.onLocationResult(locationResult);
|
|
122
|
-
List<Location> locations = locationResult.getLocations();
|
|
123
|
-
if (!locations.isEmpty()) {
|
|
124
|
-
callback.onSuccess(LocationEngineResult.create(locations));
|
|
125
|
-
} else {
|
|
126
|
-
callback.onFailure(new Exception("Unavailable location"));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
@VisibleForTesting
|
|
132
|
-
static final class GoogleLastLocationEngineCallbackTransport
|
|
133
|
-
implements OnSuccessListener<Location>, OnFailureListener {
|
|
134
|
-
private final LocationEngineCallback<LocationEngineResult> callback;
|
|
135
|
-
|
|
136
|
-
GoogleLastLocationEngineCallbackTransport(LocationEngineCallback<LocationEngineResult> callback) {
|
|
137
|
-
this.callback = callback;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@Override
|
|
141
|
-
public void onSuccess(Location location) {
|
|
142
|
-
callback.onSuccess(location != null ? LocationEngineResult.create(location) :
|
|
143
|
-
LocationEngineResult.create(Collections.<Location>emptyList()));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@Override
|
|
147
|
-
public void onFailure(@NonNull Exception e) {
|
|
148
|
-
callback.onFailure(e);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location.engine;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
|
|
6
|
-
import com.google.android.gms.common.ConnectionResult;
|
|
7
|
-
import com.google.android.gms.common.GoogleApiAvailability;
|
|
8
|
-
|
|
9
|
-
import org.maplibre.android.location.engine.LocationEngine;
|
|
10
|
-
import org.maplibre.android.location.engine.LocationEngineProxy;
|
|
11
|
-
|
|
12
|
-
public class GoogleLocationEngineProvider implements LocationEngineProvidable {
|
|
13
|
-
private static final String LOG_TAG = "GoogleLocationEngineProvider";
|
|
14
|
-
|
|
15
|
-
public LocationEngine getLocationEngine(Context context) {
|
|
16
|
-
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
|
|
17
|
-
LocationEngine locationEngine = new LocationEngineProxy<>(new GoogleLocationEngineImpl(context.getApplicationContext()));
|
|
18
|
-
Log.d(LOG_TAG, "GoogleLocationEngine will be used.");
|
|
19
|
-
return locationEngine;
|
|
20
|
-
} else {
|
|
21
|
-
return new DefaultLocationEngineProvider().getLocationEngine(context);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.location.engine;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import org.maplibre.android.location.engine.LocationEngine;
|
|
6
|
-
|
|
7
|
-
public class LocationEngineProvider implements LocationEngineProvidable {
|
|
8
|
-
@Override
|
|
9
|
-
public LocationEngine getLocationEngine(Context context) {
|
|
10
|
-
return new GoogleLocationEngineProvider().getLocationEngine(context);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#import <CoreLocation/CoreLocation.h>
|
|
2
|
-
|
|
3
|
-
#import "MLRNEventTypes.h"
|
|
4
|
-
#import "MLRNLocation.h"
|
|
5
|
-
#import "MLRNLocationManager.h"
|
|
6
|
-
#import "MLRNLocationManagerDelegate.h"
|
|
7
|
-
#import "MLRNLocationModule.h"
|
|
8
|
-
|
|
9
|
-
@interface MLRNLocationModule () <MLRNLocationManagerDelegate>
|
|
10
|
-
@end
|
|
11
|
-
|
|
12
|
-
@implementation MLRNLocationModule {
|
|
13
|
-
MLRNLocationManager *locationManager;
|
|
14
|
-
BOOL hasListeners;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
RCT_EXPORT_MODULE();
|
|
18
|
-
|
|
19
|
-
+ (BOOL)requiresMainQueueSetup {
|
|
20
|
-
return NO;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
- (instancetype)init {
|
|
24
|
-
if (self = [super init]) {
|
|
25
|
-
locationManager = [[MLRNLocationManager alloc] init];
|
|
26
|
-
locationManager.delegate = self;
|
|
27
|
-
}
|
|
28
|
-
return self;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
- (void)startObserving {
|
|
32
|
-
[super startObserving];
|
|
33
|
-
hasListeners = YES;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
- (void)stopObserving {
|
|
37
|
-
[super stopObserving];
|
|
38
|
-
hasListeners = NO;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
42
|
-
return @[ RCT_MLRN_USER_LOCATION_UPDATE ];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
RCT_EXPORT_METHOD(start : (CLLocationDistance)minDisplacement) {
|
|
46
|
-
[locationManager start:minDisplacement];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
RCT_EXPORT_METHOD(pause) { [locationManager stop]; }
|
|
50
|
-
|
|
51
|
-
RCT_EXPORT_METHOD(stop) { [locationManager stop]; }
|
|
52
|
-
|
|
53
|
-
RCT_EXPORT_METHOD(setMinDisplacement : (CLLocationDistance)minDisplacement) {
|
|
54
|
-
[locationManager setMinDisplacement:minDisplacement];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
RCT_EXPORT_METHOD(getLastKnownLocation : (RCTPromiseResolveBlock)
|
|
58
|
-
resolve rejecter : (RCTPromiseRejectBlock)reject) {
|
|
59
|
-
MLRNLocation *lastKnownLocation = [locationManager getLastKnownLocation];
|
|
60
|
-
resolve(lastKnownLocation);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
- (void)locationManager:(MLRNLocationManager *)locationManager
|
|
64
|
-
didUpdateLocation:(MLRNLocation *)location {
|
|
65
|
-
if (!hasListeners) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (self.bridge == nil) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
[self sendEventWithName:RCT_MLRN_USER_LOCATION_UPDATE body:[location toJSON]];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.requestAndroidLocationPermissions = requestAndroidLocationPermissions;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
var _index = require("./utils/index.js");
|
|
9
|
-
async function requestAndroidLocationPermissions() {
|
|
10
|
-
if ((0, _index.isAndroid)()) {
|
|
11
|
-
const res = await _reactNative.PermissionsAndroid.requestMultiple([_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, _reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION]);
|
|
12
|
-
if (!res) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const permissions = Object.keys(res);
|
|
16
|
-
for (const permission of permissions) {
|
|
17
|
-
if (res[permission] === _reactNative.PermissionsAndroid.RESULTS.GRANTED) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
throw new Error("You should only call this method on Android!");
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=requestAndroidLocationPermissions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_index","requestAndroidLocationPermissions","isAndroid","res","PermissionsAndroid","requestMultiple","PERMISSIONS","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","permissions","Object","keys","permission","RESULTS","GRANTED","Error"],"sourceRoot":"../../src","sources":["requestAndroidLocationPermissions.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,eAAeE,iCAAiCA,CAAA,EAAqB;EAC1E,IAAI,IAAAC,gBAAS,EAAC,CAAC,EAAE;IACf,MAAMC,GAAG,GAAG,MAAMC,+BAAkB,CAACC,eAAe,CAAC,CACnDD,+BAAkB,CAACE,WAAW,CAACC,oBAAoB,EACnDH,+BAAkB,CAACE,WAAW,CAACE,sBAAsB,CACtD,CAAC;IAEF,IAAI,CAACL,GAAG,EAAE;MACR,OAAO,KAAK;IACd;IAEA,MAAMM,WAAqB,GAAGC,MAAM,CAACC,IAAI,CAACR,GAAG,CAAC;IAC9C,KAAK,MAAMS,UAAU,IAAIH,WAAW,EAAE;MACpC,IACEN,GAAG,CAACS,UAAU,CAAe,KAAKR,+BAAkB,CAACS,OAAO,CAACC,OAAO,EACpE;QACA,OAAO,IAAI;MACb;IACF;IAEA,OAAO,KAAK;EACd;EAEA,MAAM,IAAIC,KAAK,CAAC,8CAA8C,CAAC;AACjE","ignoreList":[]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { PermissionsAndroid } from "react-native";
|
|
4
|
-
import { isAndroid } from "./utils/index.js";
|
|
5
|
-
export async function requestAndroidLocationPermissions() {
|
|
6
|
-
if (isAndroid()) {
|
|
7
|
-
const res = await PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION]);
|
|
8
|
-
if (!res) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const permissions = Object.keys(res);
|
|
12
|
-
for (const permission of permissions) {
|
|
13
|
-
if (res[permission] === PermissionsAndroid.RESULTS.GRANTED) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
throw new Error("You should only call this method on Android!");
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=requestAndroidLocationPermissions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["PermissionsAndroid","isAndroid","requestAndroidLocationPermissions","res","requestMultiple","PERMISSIONS","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","permissions","Object","keys","permission","RESULTS","GRANTED","Error"],"sourceRoot":"../../src","sources":["requestAndroidLocationPermissions.ts"],"mappings":";;AAAA,SAA0BA,kBAAkB,QAAQ,cAAc;AAElE,SAASC,SAAS,QAAQ,kBAAS;AAEnC,OAAO,eAAeC,iCAAiCA,CAAA,EAAqB;EAC1E,IAAID,SAAS,CAAC,CAAC,EAAE;IACf,MAAME,GAAG,GAAG,MAAMH,kBAAkB,CAACI,eAAe,CAAC,CACnDJ,kBAAkB,CAACK,WAAW,CAACC,oBAAoB,EACnDN,kBAAkB,CAACK,WAAW,CAACE,sBAAsB,CACtD,CAAC;IAEF,IAAI,CAACJ,GAAG,EAAE;MACR,OAAO,KAAK;IACd;IAEA,MAAMK,WAAqB,GAAGC,MAAM,CAACC,IAAI,CAACP,GAAG,CAAC;IAC9C,KAAK,MAAMQ,UAAU,IAAIH,WAAW,EAAE;MACpC,IACEL,GAAG,CAACQ,UAAU,CAAe,KAAKX,kBAAkB,CAACY,OAAO,CAACC,OAAO,EACpE;QACA,OAAO,IAAI;MACb;IACF;IAEA,OAAO,KAAK;EACd;EAEA,MAAM,IAAIC,KAAK,CAAC,8CAA8C,CAAC;AACjE","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"requestAndroidLocationPermissions.d.ts","sourceRoot":"","sources":["../../../../src/requestAndroidLocationPermissions.ts"],"names":[],"mappings":"AAIA,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,OAAO,CAAC,CAwB1E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"requestAndroidLocationPermissions.d.ts","sourceRoot":"","sources":["../../../../src/requestAndroidLocationPermissions.ts"],"names":[],"mappings":"AAIA,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,OAAO,CAAC,CAwB1E"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type Permission, PermissionsAndroid } from "react-native";
|
|
2
|
-
|
|
3
|
-
import { isAndroid } from "./utils";
|
|
4
|
-
|
|
5
|
-
export async function requestAndroidLocationPermissions(): Promise<boolean> {
|
|
6
|
-
if (isAndroid()) {
|
|
7
|
-
const res = await PermissionsAndroid.requestMultiple([
|
|
8
|
-
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,
|
|
9
|
-
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
|
-
if (!res) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const permissions: string[] = Object.keys(res);
|
|
17
|
-
for (const permission of permissions) {
|
|
18
|
-
if (
|
|
19
|
-
res[permission as Permission] === PermissionsAndroid.RESULTS.GRANTED
|
|
20
|
-
) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
throw new Error("You should only call this method on Android!");
|
|
29
|
-
}
|