Can I check devices location is open or close before using geolocation
?
I want to show alert message like App need to run your location, please open your devices location
, when devices location is close.
Can I navigate to go native location setting both IOS and Android?
Like example -
componentDidMount() {
// Check condition device location is open or close.
if( DevicesLocation === 'close' ) {
alert('App need to run your location, please open your devices location');
// other process
} else {
navigator.geolocation.getCurrentPosition(
(position) => {
var initialPosition = JSON.stringify(position);
this.setState({ initialPosition});
},
(error) => console.log(error.message)
);
}
}
So to ask permissions, React Native has a prebuilt feature in it which we can import and use it in our code. import { PermissionsAndroid } from 'react-native'; Before asking permissions to the user we have to declare that permissions in AndroidManifest. xml file.
I think you can use
navigator.geolocation.getCurrentPosition(
(position) => {
//do stuff with location
},
(error) => {
this.setState({locationEnabled: false}),
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
For opening settings from your app, I think you will have to get your hands dirty with native code :D
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