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

Android - Location request timed out

Open vvscode opened this issue 5 years ago • 24 comments

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

  • Android: 6.0 (varios in fact)
  • @react-native-community/geolocation: 2.0.2
  • react-native: 0.61.5
  • react: 16.12.0

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

vvscode avatar Jan 16 '20 09:01 vvscode

Try to use:

enableHighAccuracy: false

=(

fukhaos avatar Jan 17 '20 17:01 fukhaos

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

HugoLiconV avatar Jan 17 '20 20:01 HugoLiconV

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

Sofianio avatar May 14 '20 12:05 Sofianio

It works by removing enableHighAcurracy and maximumAge

joaovitorzv avatar Jun 06 '20 11:06 joaovitorzv

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.

faustoct1 avatar Jun 11 '20 19:06 faustoct1

work for me

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

irosadie avatar Jun 23 '20 02:06 irosadie

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.

GuilhermeTrivilin avatar Jul 19 '20 21:07 GuilhermeTrivilin

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

djguruwap avatar Aug 08 '20 18:08 djguruwap

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

Temirtator avatar Aug 13 '20 09:08 Temirtator

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.

gertvdkolk avatar Sep 10 '20 12:09 gertvdkolk

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.

sabrimev avatar Dec 01 '20 17:12 sabrimev

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

angeljerry0047 avatar May 20 '21 15:05 angeljerry0047

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.

TommyLeong avatar May 26 '21 12:05 TommyLeong

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

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

rajAmukhliS avatar Jul 02 '21 05:07 rajAmukhliS

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 .

angeljerry0047 avatar Jul 02 '21 11:07 angeljerry0047

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

ghiovani666 avatar Oct 04 '21 05:10 ghiovani666

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.

angeljerry0047 avatar Oct 04 '21 08:10 angeljerry0047

Increasing the timeout time worked for me guys!

Shahdurran avatar Jan 02 '22 18:01 Shahdurran

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

danielcnascimento avatar Jan 04 '22 18:01 danielcnascimento

This worked for me too! Thanks mate @danielcnascimento

vipulchakravarthy avatar Feb 04 '22 17:02 vipulchakravarthy

It works by removing enableHighAcurracy and maximumAge

This works, confirmed. Thank You

burhan3759 avatar Feb 10 '22 03:02 burhan3759

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

fk3584715 avatar May 08 '22 06:05 fk3584715

for me following solution is working

{

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

VhoraAbdulrauf avatar Jan 27 '24 06:01 VhoraAbdulrauf