React-native: Geolocation timed out, code 3

Created on 17 Mar 2017  路  14Comments  路  Source: facebook/react-native

Description

I have geolocation running in my app, followed examples described in docs. IOS version works fine, android however works only on non xiaomi devices. I tried on 2 xiamomi devices, and got Location request timed out error. While on samsung devices it works fine.

Reproduction

navigator.geolocation.getCurrentPosition(
            (position) => {
                let initialPosition = JSON.stringify(position);
                console.log(initialPosition);
            },
            (error) => console.log(JSON.stringify(error)),
            {enableHighAccuracy: Platform.OS != 'android', timeout: 2000, maximumAge: 2000 }
        );

Solution

Need to find a way either provide reason why timed out, or just fix it.

Additional Information

  • React Native version: 0.42
  • Platform: Android
  • Operating System: Mac OS
  • Dev tools: Android SDK v23
Locked

Most helpful comment

For anyone else struggling with this issue on android, try removing the maximumAge: 2000 option parameter. This option was causing geolocation to either timeout or crash the app.

I'm running react-native 0.46.4 btw.

All 14 comments

Need to check permissions on some devices before requesting navigator.geolocation.getCurrentPosition(...):

Use https://github.com/lucasferreira/react-native-android-permissions or https://facebook.github.io/react-native/docs/permissionsandroid.html

Duplicated of #7495

Have same issue, too. Check permission is not enough. See my answer at https://github.com/facebook/react-native/issues/7495#issuecomment-287793663

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

For anyone else struggling with this issue on android, try removing the maximumAge: 2000 option parameter. This option was causing geolocation to either timeout or crash the app.

I'm running react-native 0.46.4 btw.

I am also struggling for the same issue. let me know if anybody have solution for this.

I am using RN 0.48

Has anybody find a solution for this ?

Duplicate #7495

when working with map:

  1. Set permission if you build app with SDK >23 (android)
  2. if enableHighAccuracy is on, in that case, check if your phone is Enabled.

For those of you who still are experiencing this issue, I was able to solve it by omitting the parameter _maxAge_, e.g. {enableHighAccuracy: true, timeout: 5000}).

At least I can confirm this with API level 23 and RN 0.51. I also used had

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

in the AndroidManifest.xml file.

About not using _maxAge_: a pull request mentions an issue with it (https://github.com/Clintal/react-native-picker/commit/320003e1dbf6ac03798b9f6842eaa4f1bf77c4eb)

{ enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 },

Make "enableHighAccuracy: false" works for me

Guys....removing maximumAge solved the problem

@digvijayMobantica , setting enableHighAccuracy: false is strongly not encouraged

You can verify the permission before calling getCurrentPosition

 if (Platform.OS === 'android') {
      const granted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
      if (!granted) {
        return;
      }
    }
...

EDIT : Actually just forgot to turn on the GPS option on my emulator -..-

Was this page helpful?
0 / 5 - 0 ratings

Related issues

despairblue picture despairblue  路  3Comments

grabbou picture grabbou  路  3Comments

josev55 picture josev55  路  3Comments

TrakBit picture TrakBit  路  3Comments

DreySkee picture DreySkee  路  3Comments