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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/MapLibreReactNative.podspec +1 -1
  2. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +5 -5
  3. package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCamera.kt +27 -39
  4. package/android/src/main/java/org/maplibre/reactnative/events/constants/EventKeys.java +0 -4
  5. package/android/src/main/java/org/maplibre/reactnative/events/constants/EventTypes.java +0 -1
  6. package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.kt +165 -0
  7. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationMode.kt +0 -1
  8. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.kt +15 -0
  9. package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.kt +40 -0
  10. package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.kt +18 -0
  11. package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.kt +8 -0
  12. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +153 -0
  13. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +0 -5
  14. package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
  15. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.kt +131 -0
  16. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.kt +28 -0
  17. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.kt +10 -0
  18. package/ios/modules/location/MLRNLocation.h +0 -1
  19. package/ios/modules/location/MLRNLocation.m +3 -3
  20. package/ios/modules/location/MLRNLocationManager.h +1 -3
  21. package/ios/modules/location/MLRNLocationManager.m +1 -4
  22. package/ios/modules/location/MLRNLocationManagerDelegate.h +0 -2
  23. package/ios/modules/location/MLRNLocationModule.h +4 -4
  24. package/ios/modules/location/MLRNLocationModule.mm +56 -0
  25. package/ios/modules/mlrn/MLRNModule.m +0 -5
  26. package/ios/utils/MLRNEventTypes.h +0 -2
  27. package/ios/utils/MLRNEventTypes.m +0 -2
  28. package/lib/commonjs/components/user-location/UserLocation.js +3 -3
  29. package/lib/commonjs/components/user-location/UserLocation.js.map +1 -1
  30. package/lib/commonjs/index.js +2 -2
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/modules/location/LocationManager.js +46 -57
  33. package/lib/commonjs/modules/location/LocationManager.js.map +1 -1
  34. package/lib/commonjs/modules/location/NativeLocationModule.js +9 -0
  35. package/lib/commonjs/modules/location/NativeLocationModule.js.map +1 -0
  36. package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js +14 -0
  37. package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js.map +1 -0
  38. package/lib/module/components/user-location/UserLocation.js +3 -3
  39. package/lib/module/components/user-location/UserLocation.js.map +1 -1
  40. package/lib/module/index.js +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/modules/location/LocationManager.js +45 -57
  43. package/lib/module/modules/location/LocationManager.js.map +1 -1
  44. package/lib/module/modules/location/NativeLocationModule.js +5 -0
  45. package/lib/module/modules/location/NativeLocationModule.js.map +1 -0
  46. package/lib/module/modules/location/requestAndroidLocationPermissions.js +11 -0
  47. package/lib/module/modules/location/requestAndroidLocationPermissions.js.map +1 -0
  48. package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts +3 -3
  49. package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/src/index.d.ts +2 -2
  51. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +42 -22
  53. package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +24 -0
  55. package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
  57. package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
  58. package/lib/typescript/module/src/components/user-location/UserLocation.d.ts +3 -3
  59. package/lib/typescript/module/src/components/user-location/UserLocation.d.ts.map +1 -1
  60. package/lib/typescript/module/src/index.d.ts +2 -2
  61. package/lib/typescript/module/src/index.d.ts.map +1 -1
  62. package/lib/typescript/module/src/modules/location/LocationManager.d.ts +42 -22
  63. package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
  64. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +24 -0
  65. package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -0
  66. package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts +5 -0
  67. package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts.map +1 -0
  68. package/package.json +5 -3
  69. package/src/components/user-location/UserLocation.tsx +9 -7
  70. package/src/index.ts +3 -2
  71. package/src/modules/location/LocationManager.ts +90 -97
  72. package/src/modules/location/NativeLocationModule.ts +31 -0
  73. package/src/modules/location/requestAndroidLocationPermissions.ts +8 -0
  74. package/android/src/main/java/org/maplibre/reactnative/events/LocationEvent.java +0 -100
  75. package/android/src/main/java/org/maplibre/reactnative/events/TrackUserLocationChangeEvent.kt +0 -24
  76. package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.java +0 -160
  77. package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationState.java +0 -15
  78. package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.java +0 -59
  79. package/android/src/main/java/org/maplibre/reactnative/location/engine/DefaultLocationEngineProvider.java +0 -18
  80. package/android/src/main/java/org/maplibre/reactnative/location/engine/LocationEngineProvidable.java +0 -9
  81. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.java +0 -158
  82. package/android/src/main/location-engine-default/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
  83. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineImpl.java +0 -151
  84. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/GoogleLocationEngineProvider.java +0 -24
  85. package/android/src/main/location-engine-google/org/maplibre/reactnative/location/engine/LocationEngineProvider.java +0 -12
  86. package/ios/modules/location/MLRNLocationModule.m +0 -76
  87. package/lib/commonjs/requestAndroidLocationPermissions.js +0 -25
  88. package/lib/commonjs/requestAndroidLocationPermissions.js.map +0 -1
  89. package/lib/module/requestAndroidLocationPermissions.js +0 -21
  90. package/lib/module/requestAndroidLocationPermissions.js.map +0 -1
  91. package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts +0 -2
  92. package/lib/typescript/commonjs/src/requestAndroidLocationPermissions.d.ts.map +0 -1
  93. package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts +0 -2
  94. package/lib/typescript/module/src/requestAndroidLocationPermissions.d.ts.map +0 -1
  95. package/src/requestAndroidLocationPermissions.ts +0 -29
@@ -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
- }
@@ -1,9 +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 interface LocationEngineProvidable {
8
- LocationEngine getLocationEngine(Context context);
9
- }
@@ -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
- }