michalchudziak / react-native-geolocation

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

Android - Location request timed out #90

Open vvscode opened 4 years ago

vvscode commented 4 years ago

Environment

System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 59.02 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.14.0 - ~/.config/nvm/12.14.0/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.config/nvm/12.14.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.12.0 => 16.12.0
    react-native: 0.61.5 => 0.61.5
  npmGlobalPackages:
    react-native-cli: 2.0.1

Platforms

Android

Versions

Description

I use code

  return new Promise(resolve =>
    /* global navigator */
    Geolocation.getCurrentPosition(
      (...args) => {
        console.log('getCurrentPosition', args);
        // debugger;
        resolve(true);
      },
      err => {
        console.log('getCurrentPosition.error', err);
        // debugger;
        resolve(false);
      },
      {
        // enableHighAccuracy: true,
        // timeout: 20000,
        maximumAge: 1000,
      },
    ),
  );

and it gives me

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

I checked settings - location services is on, permissions provided (plus other package react-native-background-geolocation ) get's location fine

fukhaos commented 4 years ago

Try to use:

enableHighAccuracy: false

=(

HugoLiconV commented 4 years ago

Try to use:

enableHighAccuracy: false

=(

That sometimes works, I solved by changing the library https://github.com/react-native-community/react-native-geolocation/issues/43#issuecomment-573443763. I tested in a few devices and everything seems working fine but I haven't tested in production. When I have more information I will let you know

Sofianio commented 4 years ago

For me i found that removing the maximumAge solves the timeout issue

joaovitorzv commented 4 years ago

It works by removing enableHighAcurracy and maximumAge

faustoct1 commented 4 years ago

It's an issue has been here for a long time. It's a serious issue for basic usage of the lib. getCurrentPosition has been used in +90% of the cases and it doesn't work properly on Android.

irosadie commented 4 years ago

work for me

Geolocation.getCurrentPosition((success)=>{console.log(success)}, (e)=>{console.log(e)}, {timeout: 20000});

GuilhermeTrivilin commented 4 years ago

Try to use:

enableHighAccuracy: false

=(

Worked for me!

    const getUserCurrentLocation = () => {
        let latitude, longitude

        Geocoder.init(google_api_key)
        Geolocation.getCurrentPosition(
            info => {
                const { coords } = info

                latitude = coords.latitude
                longitude = coords.longitude

                setLat(latitude)
                setLng(longitude)

                getUserCurrentAddress(latitude, longitude)
            },
            error => console.log(error),
            {
                enableHighAccuracy: false,
                timeout: 2000,
                maximumAge: 3600000
            }
        )
    }

NOTE: Attention to the order of the parameters passed to the function "Geolocation.getCurrentPosition"! They must be in that order: success function, error function and parameters.

djguruwap commented 4 years ago

Try it out: useEffect(()=>{ setTimeOut(() => { getCurrentPosition() },1000) },[])

Temirtator commented 4 years ago

The main problem is, if you turn off enableHighAccuracy, position determination by geolocation is downgrading. I met this problem several times, and always had a problem

gertvdkolk commented 4 years ago

Same issue... In this post I read that this issue occurs depending on Android SDK version. Can anyone tell me if this is true? If so the lib should mention so in the docs, right?

I tested it on an AVD simulator with SDK 29 and it worked fine... But when I test on a real device with android 8.1.0 this doesn't work and my request times out..

Removing the [maximumAge] doesn't solve it for me and setting [enableHighAccuracy] to false is a no-op for me.

sabrimev commented 3 years ago

I have tried many ways to fix this issue and non of them properly worked. It works on most of devices but in some cases its not even work on them and the error is always location request timed out. This is a serious bug and there is no proper error information, plus no permission or Google Play Services check in Android devices.

image

I am going to take a chance and try this library as its created based on this issue.

UPDATE: I am writing this after almost 2 years of this comment and received no issue after using react-native-geolocation-service.

angeljerry0047 commented 3 years ago

Hi, @joaovitorzv Thank you. Among solutions above, yours solved my problem. you are amazing!

TommyLeong commented 3 years ago

Hi, @joaovitorzv Thank you. Among solutions above, yours solved my problem. you are amazing!

Just to mention, the suggestion given by @joaovitorzv is not a solution but a workaround for not using HighAccuracy of GPS location.

rajAmukhliS commented 3 years ago

, error => console.log(error), { enableHighAccuracy: false, timeout: 2000, maximumAge: 3600000 }

jazakALLAH dudes this helps me to solve the above error happy coding :)

angeljerry0047 commented 3 years ago

Thanks so much, I appreciate

On Fri, Jul 2, 2021 at 1:12 PM rajAmukhliS @.***> wrote:

, error => console.log(error), { enableHighAccuracy: false, timeout: 2000, maximumAge: 3600000 }

jazakALLAH dudes this helps me to solve the above error happy coding :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/react-native-geolocation/react-native-geolocation/issues/90#issuecomment-872719476, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALQOYD5HX4X3IEI2OPLBE73TVVDDDANCNFSM4KHQ6O7Q .

ghiovani666 commented 3 years ago

It seems to @react-native-community/geolocation not work properly.

You can follow this issue (on the official GitHub page) to receive a future answer.

But for now, you can use react-native-geolocation-service without any problems.

import Geolocation from 'react-native-geolocation-service'; ...

componentDidMount() { if (hasLocationPermission) { Geolocation.getCurrentPosition( (position) => { console.log(position); }, (error) => { // See error code charts below. console.log(error.code, error.message); }, { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } ); } } https://github.com/Agontuk/react-native-geolocation-service

angeljerry0047 commented 3 years ago

Thanks

On Mon, Oct 4, 2021 at 1:48 PM Jorge Jhovani Valverde León < @.***> wrote:

It seems to @react-native-community/geolocation not work properly.

You can follow this issue (on the official GitHub page) to receive a future answer.

But for now, you can use react-native-geolocation-service without any problems.

import Geolocation from 'react-native-geolocation-service'; ...

componentDidMount() { if (hasLocationPermission) { Geolocation.getCurrentPosition( (position) => { console.log(position); }, (error) => { // See error code charts below. console.log(error.code, error.message); }, { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } ); } } https://github.com/Agontuk/react-native-geolocation-service

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/react-native-geolocation/react-native-geolocation/issues/90#issuecomment-933161863, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALQOYDZV5ECGLRZMN6CNS3TUFE5ZPANCNFSM4KHQ6O7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Shahdurran commented 2 years ago

Increasing the timeout time worked for me guys!

danielcnascimento commented 2 years ago

All solutions above didn't work for me, so i tried just setting enableHighAccuracy as true. I got some references from this doc: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition

vipulchakravarthy commented 2 years ago

This worked for me too! Thanks mate @danielcnascimento

burhan3759 commented 2 years ago

It works by removing enableHighAcurracy and maximumAge

This works, confirmed. Thank You

fk3584715 commented 2 years ago

so guys its not the issue of codding or appllication its the isssue of mobile i have the same poblem but after changing my mobile everything is worked correctly

VhoraAbdulrauf commented 9 months ago

for me following solution is working

{

        // enableHighAccuracy: false,
        timeout: 15000,
        // maximumAge: 10000,
      },