getCurrentPositionAsync doesn't return any value...(infinity loading)

I am developing GPS based service in EXPO sdk 32.
First, use Location.getgetCurrentPositionAsync() to get the GPS value. On the iPhone, there is a return immediately, but Android will wait indefinitely for no return.

I have forced timeout, but I need this return value. Permission is normal.
I use a apple iphoneX(ios 12) and samsung galaxy note4 (SM-N916L, android 6.0.1)

It works well with Google Maps using GPS information. If the GPS information is correct, it is not a malfunction.

The code below is the same as removing Platform.OS and making it the same as Location.getCurrentPositionAsync(). I also tried accuracy to Low. it just same result…

Please help!

if (Platform.OS === "android") {
  location = await this._getLocationForAndroid(Location.Accuracy.Balanced);
} else if (Platform.OS === "ios") {
  location = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.High});
}


//this is _getLocationForAndroid function
  const GPS_TIMEOUT = 7 * 1000;
  await Promise.race([
    Location.getCurrentPositionAsync({
      accuracy: accuracy,
      maximumAge: 60000
    }),
    new Promise((resolve, reject) => {
      setTimeout(() => {
        reject(new Error("Promise execution timed out."));
      }, GPS_TIMEOUT);
    })
  ])
    .then(location => {
      return location;
    })
    .catch(error => {
      //handle location variable
    });
2 Likes

Hey @chanho, could you try using this example snack? Let me know if that resolves correctly with an Android device :+1:

@charliecruzan
Thanks for your answer. I try using your example source. and result is failed. weird point is that once in 10 times, the GPS value is successfully return. this is console log.

location
The following APIs have moved to separate packages and importing them from the "expo" package is deprecated: Location, Permissions.

1. Add correct versions of these packages to your project using:

   expo install expo-location expo-permissions

   If "install" is not recognized as an expo command, update your expo-cli installation.

2. Change your imports so they use specific packages instead of the "expo" package:

 - import { Location } from 'expo' -> import * as Location from 'expo-location'
 - import { Permissions } from 'expo' -> import * as Permissions from 'expo-permissions'


[Unhandled promise rejection: Error: Location provider is unavailable. Make sure that location services are enabled.]
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:155:41 in createErrorFromErrorData
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:104:55 in <unknown>
- ... 5 more stack frames from framework internals
1 Like

Looks like you need to enable location services on the device. If you can reproduce this on and Android Emulator, just let me know which one and I will try on my end

But I already enable location services on my device. (wifi is connected, and the carrier is not connected.)
As a result, GPS information is returned 1 in 30 times. In most cases, however, the return value does not come. Is there anything I need to check?

I think you’ve already found/commented on this relevant github issue- Android Location.getCurrentPositionAsync as per sdk32 docs not working, but as per sdk31 docs is working · Issue #4304 · expo/expo · GitHub, thanks! I’ve assigned it, but if you could provide exact steps to repro and post them there, it would help the engineer assigned a lot!

I faced same issue.
It is strange because it worked yesterday but today I got this error.
And I get this error on SM-G9350 but on SM-G930S it works well.
It is very strange and I am wonder if this location function is working with standalone apps on all devices.

1 Like

@charliecruzan
Sorry. I’m saw it late.
I built the app and run it standalone. When I try on a LTE network, I can’t get a GPS signal on the iPhone. (iPhoneX)
Is it an official expo bug?

1 Like

We have a github issue for it (linked above), but it’s not a confirmed bug yet (need you to provide a repro, a snack works well, so that we can replicate the behavior)

Good news! I don’t know why, but I get GPS in android when I code below.

Location.getCurrentPositionAsync({})    // no options
  .then(location => {
      this.setState({ location: location.coords });
  }).catch(.....)

However, I could not get it when the code below.

location = await this._getLocationPosition({ accuracy: Location.Accuracy.Balanced});
this.setState({
  location: location.coords
});

So I divided the code of Android and iPhone through condition.

if (Platform.OS === "android") {
   ... // no options
} else{
   ...  // with accuracy options
}

Condition: WIFI off / LTE (in Korea) / Expo SDK32

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.