Skip to content

Commit 0c15385

Browse files
committed
Android: expose option to use LocationManager API
1 parent 1b1e6ba commit 0c15385

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

android/src/main/java/com/agontuk/RNFusedLocation/LocationOptions.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class LocationOptions {
1818
private final double maximumAge;
1919
private final boolean showLocationDialog;
2020
private final boolean forceRequestLocation;
21+
private final boolean forceLocationManager;
2122

2223
private LocationOptions(
2324
LocationAccuracy accuracy,
@@ -27,7 +28,8 @@ private LocationOptions(
2728
long timeout,
2829
double maximumAge,
2930
boolean showLocationDialog,
30-
boolean forceRequestLocation
31+
boolean forceRequestLocation,
32+
boolean forceLocationManager
3133
) {
3234
this.accuracy = accuracy;
3335
this.interval = interval;
@@ -37,6 +39,7 @@ private LocationOptions(
3739
this.maximumAge = maximumAge;
3840
this.showLocationDialog = showLocationDialog;
3941
this.forceRequestLocation = forceRequestLocation;
42+
this.forceLocationManager = forceLocationManager;
4043
}
4144

4245
public static LocationOptions fromReadableMap(ReadableMap map) {
@@ -60,7 +63,8 @@ public static LocationOptions fromReadableMap(ReadableMap map) {
6063
!map.hasKey("showLocationDialog") || map.getBoolean("showLocationDialog");
6164
boolean forceRequestLocation =
6265
map.hasKey("forceRequestLocation") && map.getBoolean("forceRequestLocation");
63-
66+
boolean forceLocationManager =
67+
map.hasKey("forceLocationManager") && map.getBoolean("forceLocationManager");
6468

6569
return new LocationOptions(
6670
accuracy,
@@ -70,7 +74,8 @@ public static LocationOptions fromReadableMap(ReadableMap map) {
7074
timeout,
7175
maximumAge,
7276
showLocationDialog,
73-
forceRequestLocation
77+
forceRequestLocation,
78+
forceLocationManager
7479
);
7580
}
7681

@@ -106,6 +111,10 @@ public boolean isForceRequestLocation() {
106111
return forceRequestLocation;
107112
}
108113

114+
public boolean isForceLocationManager() {
115+
return forceLocationManager;
116+
}
117+
109118
/**
110119
* Determine location priority from user provided accuracy level
111120
*/

android/src/main/java/com/agontuk/RNFusedLocation/RNFusedLocationModule.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void getCurrentPosition(ReadableMap options, final Callback success, fina
7373
}
7474

7575
LocationOptions locationOptions = LocationOptions.fromReadableMap(options);
76-
final LocationProvider locationProvider = createLocationProvider();
76+
final LocationProvider locationProvider = createLocationProvider(locationOptions.isForceLocationManager());
7777

7878
final String key = "provider-" + singleLocationProviderKeyCounter;
7979
singleLocationProviders.put(key, locationProvider);
@@ -109,7 +109,7 @@ public void startObserving(ReadableMap options) {
109109
LocationOptions locationOptions = LocationOptions.fromReadableMap(options);
110110

111111
if (continuousLocationProvider == null) {
112-
continuousLocationProvider = createLocationProvider();
112+
continuousLocationProvider = createLocationProvider(locationOptions.isForceLocationManager());
113113
}
114114

115115
continuousLocationProvider.requestLocationUpdates(locationOptions, new LocationChangeListener() {
@@ -133,14 +133,15 @@ public void stopObserving() {
133133
}
134134
}
135135

136-
private LocationProvider createLocationProvider() {
136+
private LocationProvider createLocationProvider(boolean forceLocationManager) {
137137
ReactApplicationContext context = getContext();
138+
boolean playServicesAvailable = LocationUtils.isGooglePlayServicesAvailable(context);
138139

139-
if (LocationUtils.isGooglePlayServicesAvailable(context)) {
140-
return new FusedLocationProvider(context);
140+
if (forceLocationManager || !playServicesAvailable) {
141+
return new LocationManagerProvider(context);
141142
}
142143

143-
return new LocationManagerProvider(context);
144+
return new FusedLocationProvider(context);
144145
}
145146

146147
private void emitEvent(String eventName, WritableMap data) {

0 commit comments

Comments
 (0)