michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.32k stars 232 forks source link

Function getCurrentPosition always returns timeout error on Android #66

Open igordevelops opened 5 years ago

igordevelops commented 5 years ago

Platforms

Android

Versions

Description

Function Geolocation.getCurrentPosition always returns error on Android

Location request timed out

{ "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out" }

I've tried to add timeout and maximumAge options but it doesn't help me.

return new Promise(resolve => {
    Geolocation.getCurrentPosition(
      position => {
        const { latitude, longitude } = position.coords;

        resolve({ latitude, longitude });
      },
      err => resolve(err),
      {
        enableHighAccuracy: true,
        timeout: 100,
        maximumAge: 0,
      }
    );
  });

Reproducible Demo

maxencehenneron commented 5 years ago

It's probably because you have enableHighAccuracy set to true. When you're in a building, the phone fails to accurately locate you and times out. What I did is:

mfharding commented 5 years ago

I am also getting this error lately. I am using the following code:


      initialPosition => {
        // Alert.alert(JSON.stringify(initialPosition))
        this.savePosition(initialPosition);
      },
      error =>
        console.log("The location could not be loaded because ", error.message),
      { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 }
    );```
maulikdhameliya commented 5 years ago

I am also facing this issue on Android 9 Phone. Same App working fine on other phones but on this device never able to get currentPosition using geolocation api

halaharr commented 5 years ago

Getting the same error, is there another plugin that works better?

mikebouwmans commented 5 years ago

Getting the same error after upgrading to sdk 28

mrbrentkelly commented 5 years ago

~Getting same issue after upgrading to react native 0.61. Not passing any configuration, simply calling Geolocation.getCurrentPosition((info): void => { /* do something*/ });~

Update: Added <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> to the AndroidManifest.xml and the issue went away 👍

mauriziocarella commented 5 years ago

I'm getting same issue if I set maximumAge with react native version 0.61.2

Therises commented 4 years ago

Getting same issue with default and with different options. On emulator it works fine, but on actual device - no. And given this bug exists for about 3 years now guess it wouldn't be fixed.

azhaubassar commented 4 years ago

I have the same error, any solutions? :(

espipj commented 4 years ago

Same error here! I suggest to use https://github.com/Agontuk/react-native-geolocation-service which uses react-native-geolocation under the hood on iOS but works flawlessly on Android. 😄 @azhaubassar

bottle-rocket-11 commented 4 years ago

Hey guys, I have also received this issue lately. When you add a timeout in the config like ...,{timeout: 10000} you WILL receive this error just ten seconds later. I thought it would give it more time to return successfully but no....

tayfunyasar commented 4 years ago

I'm facing same issue with my physical device. Works fine in emulator.

edit: i applied @espipj 's suggestion and its working now.

switch13 commented 4 years ago

I'm getting the same error in ios: "Unable to fetch location within 10.0s." Changed timeout to 100s, still no luck.

I ran into something similar a while back and noticed that the permissions popup never triggered and the same thing is happing here.

I just added the following to componentDidMount() Geolocation.setRNConfiguration({ authorizationLevel: 'whenInUse', skipPermissionRequests: false, }); After accepting the permission it works! But now I run into the problem of timing.

I have a timeout of 10 seconds on the getCurrentPosition but if I don't accept the permissions popup quickly enough, the error still triggers.

There doesn't seem to be any convenient way to check if a permission has been accepted besides installing another library to check if accepted, then call getCurrentPosition.

Anyone have a good solution to this one?

ravi-pandit14 commented 4 years ago

@jbinda @jainkuniya @tyronet-sportsbet Any Solution of this issue????

espipj commented 4 years ago

I think this hasn't been fixed yet (in this module) @ravi-pandit14

Temirtator commented 4 years ago

is there any solution for this case?

ravi-pandit14 commented 4 years ago

@espipj I have tried all of the cases but not success. If geolocation are working fine for you, it would be really helpful if you could provide a sample public repo or complete code.

espipj commented 4 years ago

Hey @ravi-pandit14 as mentioned in previous comments react-native-geolocation-service works, it has a good readme with examples

Temirtator commented 4 years ago

Hey @ravi-pandit14 as mentioned in previous comments react-native-geolocation-service works, it has a good readme with examples

@espipj there is problem with geolocation when u testing on some mobile phones, im getting(as mentioned above) permission denied error, but not in all mobile phones

{ "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out" }

yurii-oliiarnyk commented 4 years ago

Is there any update?

Temirtator commented 4 years ago

@yurii-oliiarnyk https://github.com/Agontuk/react-native-geolocation-service solves problem, change youre library

Adr1ann commented 4 years ago

Remove completely maximumAge param. It worked for me.

ebnersilva commented 4 years ago

The solution of @Temirtator works for me. Thanks!

MuriloDutraProjects commented 3 years ago

Hey guys, I have also received this issue lately. When you add a timeout in the config like ...,{timeout: 10000} you WILL receive this error just ten seconds later. I thought it would give it more time to return successfully but no....

@hugopretorius914 thanks man, that helped me! But I didn't do exactly what you said.

What I noticed is when I set this way below, it doesn't work at all:

{
    enableHighAccuracy: false,
    timeout: 20000
}

But if I set this way, it works!

{
    enableHighAccuracy: true,
    timeout: 20000
}

This way works as well, like you said:

{
      enableHighAccuracy: false,   //or true
}

I don't know why it's working this way, but it works! I hope this can help somebody else.

By the way, I'm not using this lib, instead the one I have installed in my project is: https://github.com/Agontuk/react-native-geolocation-service

"react-native-geolocation-service": ^5.1.1 "react": "17.0.1", "react-native": "0.63.4", Windows 10

BinMansoor11 commented 3 years ago

Remove completely maximumAge param. It worked for me.

It worked for me.

julian141094 commented 3 years ago

Tengo el mismo problema si configuro maximumAgecon la versión nativa de reacción0.61.2 24/06/2021 I have this problem, delete the maximumAge (or comment) and run again, this work for me!! Thanz @mauriziocarella

Ashkarpr commented 3 years ago

Hey @ravi-pandit14 as mentioned in previous comments react-native-geolocation-service works, it has a good readme with examples

@espipj there is problem with geolocation when u testing on some mobile phones, im getting(as mentioned above) permission denied error, but not in all mobile phones

{ "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out" } https://github.com/react-native-geolocation/react-native-geolocation/issues/66#issuecomment-579894886

cybergears commented 2 years ago

My problem is similar to some extent. I have set the enableHighAccuracy to True. Sometimes it works fine but other times it returns Request Time Out response. I have increased the timeout limit to 150000 ms and maximumAge to 0, I have also added the FIN_Location permission in android manifest file. I think either the API is unstable or the surrounding factor is the issue. If i set the high accuracy to false then accuracy drops.

efkan commented 1 year ago

The issue persists on the Android emulator with APIs 29 and 30.

Setting options solve my problem as a workaround.

image