I am trying figure out how to listen to event when the user turns on or off the location in the settings. I tried navigator.geolocation.watchposition but didn't have much success, since it does not listen to the respective event.
npm install --save react-native-location
react-native link
var React = require('react-native');
var { DeviceEventEmitter } = React;
var { RNLocation: Location } = require('NativeModules');
Location.getAuthorizationStatus(function(authorization) {
//authorization is a string which is either "authorizedAlways",
//"authorizedWhenInUse", "denied", "notDetermined" or "restricted"
});
Location.requestAlwaysAuthorization();
Location.startUpdatingLocation();
Location.setDistanceFilter(5.0);
var subscription = DeviceEventEmitter.addListener(
'locationUpdated',
(location) => {
/* Example location returned
{
coords: {
speed: -1,
longitude: -0.1337,
latitude: 51.50998,
accuracy: 5,
heading: -1,
altitude: 0,
altitudeAccuracy: -1
},
timestamp: 1446007304457.029
}
*/
}
);
Refer to this site for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With