michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.31k stars 227 forks source link

getCurrentPosition throws CODE 1 error on iOS #139

Open pabichw opened 3 years ago

pabichw commented 3 years ago

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?

pku-arun commented 3 years ago

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

infazA commented 3 years ago

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

Leehee1on commented 3 years ago

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

0x1bitcrack3r commented 3 years ago

Any other workaround instead of installing new npm package?

0x1bitcrack3r commented 3 years ago

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

infazA commented 3 years ago

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

pabichw commented 3 years ago

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

nica0012 commented 3 years ago

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?

kartavyaparekh96 commented 3 years ago

This also happens to me too.

nica0012 commented 3 years ago

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

nica0012 commented 3 years ago

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

0x1bitcrack3r commented 3 years ago

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

nica0012 commented 3 years ago

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 commented 3 years ago

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.

yasinugrl commented 3 years ago

Any solition?

alicancelik commented 3 years ago

This also happens to me too.

preflower commented 3 years ago

Some android also have this problem.

janeviceral08 commented 2 years ago

It also happens to me. any other solution?

AlexeyNovikov commented 2 years ago

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.

asafkorem commented 2 years ago

Any update here?

ismailharmanda commented 1 year ago

Any solution?