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

getCurrentPosition throws CODE 1 error on iOS

Open pabichw opened this issue 4 years ago • 22 comments

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?

pabichw avatar Jan 18 '21 18:01 pabichw

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

pku-arun avatar Jan 27 '21 04:01 pku-arun

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

infazA avatar Jan 27 '21 05:01 infazA

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

Leehee1on avatar Feb 02 '21 03:02 Leehee1on

Any other workaround instead of installing new npm package?

0x1bitcrack3r avatar Feb 11 '21 11:02 0x1bitcrack3r

@pabichw try reducing timeout value in this { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 } this solved my problem

0x1bitcrack3r avatar Feb 15 '21 04:02 0x1bitcrack3r

@pabichw Were you able to find a solution for this ?

infazA avatar Feb 17 '21 05:02 infazA

@infazA No, it didn’t happen in my teammates' builds so I decided to postpone this

pabichw avatar Feb 17 '21 07:02 pabichw

This also happens to me too. Super weird because like you said it only happens if you don't allow location right away... After waiting a couple seconds it will give you that error...? Any solutions?

nica0012 avatar Mar 02 '21 00:03 nica0012

This also happens to me too.

kartavyaparekh96 avatar Mar 02 '21 06:03 kartavyaparekh96

This is becoming a big problem for users. Has anyone resolved this?

nica0012 avatar Mar 18 '21 02:03 nica0012

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

nica0012 avatar Mar 18 '21 03:03 nica0012

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

0x1bitcrack3r avatar Mar 18 '21 03:03 0x1bitcrack3r

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 did try this with a value of 200000, but still no luck. Whenever this was happening and I did a fast refresh it would work which is why I tried my solution. I don't even want to call it a solution because it's so quick and dirty but it's a hotfix (for now) to resolve this crash that's happening for many people. This package has not been updated in a while I'm wondering if it had anything to do with new IOS versions.

nica0012 avatar Mar 18 '21 04:03 nica0012

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

I ended up going this route, works like a charm.

nica0012 avatar Mar 18 '21 19:03 nica0012

Any solition?

yasinugrl avatar Mar 23 '21 17:03 yasinugrl

This also happens to me too.

alicancelik avatar Mar 23 '21 17:03 alicancelik

Some android also have this problem.

preflower avatar May 11 '21 12:05 preflower

It also happens to me. any other solution?

janeviceral08 avatar Oct 07 '21 11:10 janeviceral08

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.

AlexeyNovikov avatar Dec 08 '21 20:12 AlexeyNovikov

Any update here?

asafkorem avatar Apr 14 '22 15:04 asafkorem

Any solution?

ismailharmanda avatar Jun 26 '23 09:06 ismailharmanda