Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I check devices location is open or close on React Native

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)
     );
  }
}
like image 831
lwinkyawmyat Avatar asked Jul 20 '16 03:07

lwinkyawmyat


People also ask

How do I ask for location permissions in React Native?

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.


1 Answers

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

like image 73
Aakash Sigdel Avatar answered Sep 23 '22 07:09

Aakash Sigdel