react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

Asking to turn on location

Open puremana opened this issue 6 years ago • 10 comments

Ask your Question

Geolocation.getCurrentPosition() requests permission which is good, but when that user doesn't have location turned on and permission is granted, location isn't enabled. Is there a way to ask the user to enable location?

Android Version 6.0.1 Latest react-native-geolcation version React Native 0.61.5

puremana avatar Dec 18 '19 04:12 puremana

Ended up wrapping my Geolocation.getCurrentPosition with RNAndroidLocationEnabler from https://github.com/Richou/react-native-android-location-enabler

puremana avatar Dec 18 '19 22:12 puremana

@puremana Can you share a sample code?

HarshitMadhav avatar Feb 13 '20 12:02 HarshitMadhav

@HarshitMadhav Along the lines of this

constructor(props) {
    super(props);
    if (Platform.OS === 'android') {
        this.getPermissions()
    } else {
        this.findCoordinates()
    }
  }

  getPermissions = () => {
    RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
    .then(data => {
      if (data === "already-enabled") {
        this.findCoordinates()
      } else {
        setTimeout(() => {
          this.findCoordinates()
        }, 1000)
      }
    })
  };

  findCoordinates = () => {
    Geolocation.getCurrentPosition(
      info => {
        this.setState({ locationInfo: info });
      },
      error => {
        console.log(error)
      });
  }

puremana avatar Feb 13 '20 19:02 puremana

@puremana Thanks a lot..

HarshitMadhav avatar Feb 14 '20 04:02 HarshitMadhav

Ended up wrapping my Geolocation.getCurrentPosition with RNAndroidLocationEnabler from https://github.com/Richou/react-native-android-location-enabler

what about ios?

Zohaib-Javed avatar Aug 27 '20 12:08 Zohaib-Javed

Ended up wrapping my Geolocation.getCurrentPosition with RNAndroidLocationEnabler from https://github.com/Richou/react-native-android-location-enabler

what about ios?

This was awhile ago but I believe iOS did it by default using this package. Atleast that is what my code is telling me. Does it not?

puremana avatar Sep 04 '20 00:09 puremana

there' s another way that not using library?

anuk112 avatar Mar 26 '21 06:03 anuk112

Coming from 2022, is this issue solved yet?

AhmadTahaluf avatar Nov 30 '22 08:11 AhmadTahaluf

hello @puremana I have tried with this code but I'm getting this error: TypeError: null is not an object (evaluating '_reactNativeAndroidLocationEnabler.default.promptForEnableLocationIfNeeded')

please check it why we are getting it even I had checked version issue.

Princejain21 avatar Mar 31 '23 10:03 Princejain21