Better error handling in Android Geolocation module (PR 2)
Summary: Just a testing PR for the shipit bot (please don't close :)) Closes https://github.com/facebook/react-native/pull/4355 Reviewed By: svcscm Differential Revision: D2702784 Pulled By: mkonicek fb-gh-sync-id: 867c65dcea486750ca65a8437b37a0f658538111
This commit is contained in:
parent
3dca8cf9fd
commit
c9dd4015f1
|
@ -107,28 +107,25 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
|||
Callback error) {
|
||||
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
||||
|
||||
LocationManager locationManager =
|
||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||
if (provider == null) {
|
||||
error.invoke("No available location provider.");
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = null;
|
||||
try {
|
||||
location = locationManager.getLastKnownLocation(provider);
|
||||
LocationManager locationManager =
|
||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||
if (provider == null) {
|
||||
error.invoke("No available location provider.");
|
||||
return;
|
||||
}
|
||||
Location location = locationManager.getLastKnownLocation(provider);
|
||||
if (location != null &&
|
||||
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
|
||||
success.invoke(locationToMap(location));
|
||||
return;
|
||||
}
|
||||
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
|
||||
.invoke();
|
||||
} catch (SecurityException e) {
|
||||
throwLocationPermissionMissing(e);
|
||||
}
|
||||
if (location != null &&
|
||||
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
|
||||
success.invoke(locationToMap(location));
|
||||
return;
|
||||
}
|
||||
|
||||
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
|
||||
.invoke();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,24 +140,23 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
|||
return;
|
||||
}
|
||||
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
|
||||
LocationManager locationManager =
|
||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||
if (provider == null) {
|
||||
emitError("No location provider available.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LocationManager locationManager =
|
||||
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
|
||||
if (provider == null) {
|
||||
emitError("No location provider available.");
|
||||
return;
|
||||
}
|
||||
if (!provider.equals(mWatchedProvider)) {
|
||||
locationManager.removeUpdates(mLocationListener);
|
||||
locationManager.requestLocationUpdates(provider, 1000, 0, mLocationListener);
|
||||
}
|
||||
mWatchedProvider = provider;
|
||||
} catch (SecurityException e) {
|
||||
throwLocationPermissionMissing(e);
|
||||
}
|
||||
|
||||
mWatchedProvider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue