react-native-geolocation: getCurrentPosition throws CODE 1 error on iOS

When location request dialog pops up getCurrentPosition function throws following error almost immediately (after 2-3 seconds). BUT, if I allow app to use location quick enough, then no error is being thrown and onSuccess() callback executes correctly.

{
  code: 1,
  message: "User denied access"
}

Code:

Geolocation.getCurrentPosition(
      (pos) => {
        console.log('got position', pos);
      },
      (err) => {
        console.error('geo Error', err);
      },
      { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 },
    );

Happens both on simulator and physical device. What is the cause?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 15
  • Comments: 21 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue for me, but change library https://github.com/Agontuk/react-native-geolocation-service

// function Geolocation.requestAuthorization(‘whenInUse’) .then((result) => { if (result === ‘granted’) { // success case } }) .catch((error) => console.log(error));

Is my solution

Did anyone find a solution for this issue ? Im also facing the same.

Any solition?

A potential fix… I re-ran the function on the catch, and well - it worked

How will you handle the error then. What if it fails again in the catch block. I don’t think this is a potential fix. Did you try increasing the timeout value { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 }, this solved my problem. I was facing the same issue in iOS 14

I am facing the same issue. Is there any fix for this?

Hi guys. I’ve created PR for this issue. https://github.com/react-native-geolocation/react-native-geolocation/pull/168 This happens on iOS 14+. Feel free to check it out and ping me here if you find any bugs.