question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Location permission request not coming both iOS and Android

See original GitHub issue

System: OS: macOS 10.15.7 CPU: (4) x64 Intel® Core™ i5-5350U CPU @ 1.80GHz Memory: 50.46 MB / 8.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 13.12.0 - /usr/local/bin/node Yarn: Not Found npm: 6.14.5 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: Not Found IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 11.7/11E801a - /usr/bin/xcodebuild Languages: Java: 11.0.8 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: react-native: Not Found

using : react-native-geolocation-service: “^5.0.0”

Not able to get permission popup. It won’t as for permission.

  componentDidMount = () => {
    Geolocation.getCurrentPosition(
      (info) => {
        let lat = info.coords.latitude;
        let lng = info.coords.longitude;
        this.getLocation(lat, lng);
      },
      (err) => {
        console.log('location err=>', err);
        alert('Location error');
      },
    );
  };

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cmcodes-uniworkscommented, Oct 24, 2020

@Agontuk I am using the following function to request permission and later calling it inside useEffect() before Geolocation.getCurrentPosition(). Getting no error and no location. Am I doing anything wrong? Can you share any working example?

  async function requestPermissions() {
    if (Platform.OS === 'ios') {
      Geolocation.requestAuthorization();
      Geolocation.setRNConfiguration({
        skipPermissionRequests: false,
        authorizationLevel: 'whenInUse',
      });
    }
    if (Platform.OS === 'android') {
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      );
    }
  }
useEffect(() => {
    requestPermissions();
    Geolocation.getCurrentPosition(
      position => { console.log("POS" + position); // not logging anything 
         setlatitude(position.coords.latitude);
         setlongitude(position.coords.longitude); },
      error => { Alert.alert(error.message.toString()); }, // no error displayed
      { showLocationDialog: true, enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
    );
  });

Also modified build.gradle & AndroidManifest.xml just like you mentioned in the docs.

0reactions
Agontukcommented, Oct 27, 2020

@Agontuk I am using the following function to request permission and later calling it inside useEffect() before Geolocation.getCurrentPosition(). Getting no error and no location. Am I doing anything wrong? Can you share any working example?

Why are you using useEffect for this ? useEffect will be called every time after render, so not a good place to use this (unless using it only once). Also setRNConfiguration is deprecated in recent versions and requestAuthorization method needs an argument. Please check the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request location permissions - Android Developers
... Bind layout views to Architecture Components · Two-way data binding ... Overview · Request location permissions · Get the last known location...
Read more >
Flutter iOS request location permission not prompting anything
It works perfectly on an Android device but not prompting anything on iOS. The target iOS version is 11 and packages that I...
Read more >
[expo-location] request permission always returns denied
Clear app state so app will ask to allow location permissions; Deny location permissions; Allow location permission from the settings; Reopen ...
Read more >
Requesting access to location in the background
You can now submit your app for feedback on location in the background access by completing the Location permissions declaration form in Play...
Read more >
Location permission alert is not showing in iPhone device.
I have added the location permission feature in my project and the permission alert is working fine on ios simulators. But in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found