michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.33k stars 234 forks source link

Location request timed out #170

Open artstylee opened 2 years ago

artstylee commented 2 years ago
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.15.14",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-navigation/bottom-tabs": "^6.0.9",
    "@react-navigation/drawer": "^6.1.8",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.2.5",
    "lottie-react-native": "^5.0.1",
    "mobx": "^6.3.11",
    "mobx-react-lite": "^3.2.3",
    "react": "17.0.2",
    "react-native": "0.66.4",
    "react-native-console-time-polyfill": "^1.2.3",
    "react-native-flipper": "^0.125.0",
    "react-native-geolocation-service": "^5.3.0-beta.4",
    "react-native-gesture-handler": "^2.1.0",
    "react-native-google-places-autocomplete": "^2.4.1",
    "react-native-maps": "^0.29.4",
    "react-native-reanimated": "^2.3.1",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "^3.10.1",
    "react-native-svg": "^12.1.1",
    "react-native-vector-icons": "^9.0.0",
    "rn-flipper-async-storage-advanced": "^1.0.4",
    "socket.io-client": "^4.4.0"
    useEffect(() => {
        Geolocation.getCurrentPosition((info) => console.log(info),
            (error) => console.log(error),
            {timeout: 1000, maximumAge: 0, enableHighAccuracy: true});
    }, [state])

without deps {timeout: 1000, maximumAge: 0, enableHighAccuracy: true}); it works good and it gives me pretty accurate coords, but the are cached(i see tampstamps) i want to see up-to-date position or see an error. no cached values needed but if i set the options object it will fail with that

Снимок

vipulchakravarthy commented 2 years ago

@artstylee Did you find any fix for this?

mawaraujo commented 2 years ago

@artstylee I've the same error with Android SDK 30+

cwilby commented 2 years ago

Ran into this issue as well, my best guess is a default timeout was decreased somewhere.

Found the solution here: https://github.com/react-native-geolocation/react-native-geolocation/blob/master/example/GeolocationExample.js#L35

Setting the timeout to 20000 worked for me.

Geolocation.getCurrentPosition(
    (info) => {},
    (error) => {},
    { timeout: 20000 }
);
UsamaDaood commented 2 years ago

I had also faced this issue (Location Request Timed out) on different Android Devices. Now, I have used the Alternative Geolocation YARN (npm) package and its work for me. Please have a look. https://github.com/Agontuk/react-native-geolocation-service#why-

Thanks. Regards. :-)

rumax commented 1 year ago

Any progress/plans on fixing the issue?

GeolocationOptions

Adding timeout: 20000 (but default has to be 10 minutes) as proposed by @cwilby or using enableHighAccuracy: true as in example seems to fix the issue, but what is the correct fix?

Also according to types definition GeolocationOptions is optional, so default options should work fine.

stantoxt commented 1 year ago

GPS provider will always get the last cached location even set {maximumAge: 0, enableHighAccuracy: true}.

Here are repro steps. 1.Create two button for getting Location from Gps and Network. 2.Click Network Provider Button,then get the network location. 3.Click Gps Provider Button,then this would return the network location, I think it used Network Provider. 4.Close network, Repeat 3 step, it would use Gps get a new location.

I think LocationManager will be downgraded to use network even set Gps,But I dont want this downgrade.