From 2b0282aa69c0bc999aef9444bff7e1dfa54cac48 Mon Sep 17 00:00:00 2001 From: daose Date: Tue, 4 Apr 2017 22:16:23 -0700 Subject: [PATCH] #11587 invoke error for getCurrentLocation Summary: It started with https://github.com/facebook/react-native/issues/11587, which reported that the error returned by `getCurrentLocation` did not match the spec. This resulted in PR https://github.com/facebook/react-native/pull/11723, which did not get merged because it was said by ide and mkonicek that simply emitting the error will cause it to hang since the `error` callback was never invoked. However, it seems like somewhere along the way PR https://github.com/facebook/react-native/pull/13140 got merged in which did exactly that. Since it now matches the spec, turning off location services on Android then running the below example code from [Geolocation](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) docs errors out correctly. ```javascript var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; function success(pos) { var crd = pos.coords; console.log('Your current po Closes https://github.com/facebook/react-native/pull/13306 Differential Revision: D4833377 Pulled By: ericvicenti fbshipit-source-id: dbea5948790a3f521751a0cc0a25f0e323b30667 --- .../com/facebook/react/modules/location/LocationModule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java index 866309241..a09ebc236 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java @@ -123,7 +123,9 @@ public class LocationModule extends ReactContextBaseJavaModule { (LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE); String provider = getValidProvider(locationManager, locationOptions.highAccuracy); if (provider == null) { - emitError(PositionError.PERMISSION_DENIED, "No location provider available."); + error.invoke(PositionError.buildError( + PositionError.PERMISSION_DENIED, + "No location provider available.")); return; } Location location = locationManager.getLastKnownLocation(provider);