Location is not working.?

#1

componentWillMount() {
if (Platform.OS === ‘android’ && !Constants.isDevice) {
this.setState({
errorMessage: ‘Oops, this will not work on Sketch in an Android emulator. Try it on your device!’,
});
} else {
this._getLocationAsync();
}
}

_getLocationAsync = async () => {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== ‘granted’) {
this.setState({
errorMessage: ‘Permission to access location was denied’,
});
}
await Location.getCurrentPositionAsync({ enableHighAccuracy: true })
.then(location => {
this.setState({ location });
})
.catch(error => {
console.log(‘error’, error);
});
};
I got an issue when i tried to run the example provided by docs as above.
Location is no any response.
I am in china. i am not sure whether it is the network issue?

0 Likes

#2

are you using ios or android?

0 Likes

#3

I am using android. And i have granted the location permissions.

0 Likes

#4

if you run this snack. does it give you the correct location on your device?

https://snack.expo.io/rJ0EuSAMb

0 Likes

#5

Hi @ccheever , I have installed expo on my android phone.
I am using XDE run the project, Host use ‘LAN’ and protocol use ‘exp’ to share to my android phone.
i wanna run the location example. but it seem not working fine.

0 Likes

#6

hi @xiezhong – did you run the snack i linked to above? you should be able to do that with just the Expo client app on your phone. What happened when you did that?

0 Likes

#7

Hi @ccheever,
First it will alert me to grant location permission.
After granted.
I just get the result as following:
Change code in the editor and watch it change on your phone! Save to get a shareable url. You get a new url each time you save.
Location:

0 Likes

#8

Nothing was listed under location? Hmmmm… That’s very strange.

What model of phone do you have? That code works fine for me so maybe theres some problem with your hardware or Android setup or a problem with the location code in React Native. Or maybe there’s some reason this doesn’t work in China?

If you use other apps on your phone that use location, do those work as expected?

0 Likes

#9

Nothing listed under location.
My phone is Huawei P9, android version is 7.0
I just tried on iphone 6, it working fine. so definitely it’s not the reason of China.
I think it’s the component issue, hope you can fix it.
Download expo from google play is difficult in China… And i don’t have any other android phone, so sorry to provide more information to you.

0 Likes

#10

Run into this topic while trying to have GPS working on Genymotion emulator. So I tried Android Emulator on linked Snack example and it doesn’t work there either. It’s working on my phone just fine. Curious what is there special about emulators that it doesn’t work. Genymotion and even the Appetize.io one has GPS emulation enabled. Yet it never resolves the promise, just keeps waiting. Might that be some internal bug in Location API with condition checking for a real device?

0 Likes

#11

I’m not sure. I’m not aware of bugs in our location code, but its possible.

In my experience, simulators/emulators are not very good at peripheral things and if you want to test that stuff, it’s always best to do it on an actual physical device.

0 Likes

#12

Yea, I understand, but GPS is one of the things that would best to be emulated. I don’t want to go running outside to just validate it’s working :slight_smile:

Have you tried running it in Snack simulator? Is that working for you? If you can reproduce it there, can it be issued as a bug? :slight_smile:

0 Likes

#13

It works here for me in the simulator:

https://snack.expo.io/Hydy8uLKZ

What SDK version are you using? If you are using an old one, upgrade to SDK 20. There might be a bug in some older SDK.

0 Likes

#14

@ccheever Have you tried Android emulator in the Snack as well? Now I see that iOS one works too, but Android does not.

0 Likes

#15

Got the same problem and make it work only after passing the maximumAge as a parameter and call it at componentDidMount(). After that I’ve received the location data (“expo”: “^23.0.0”).

0 Likes

#16

This is probably the same issue: https://github.com/expo/expo/issues/426 please check out my comment (the last one) and let us know if this works :slight_smile:

1 Like

#17

I think it is a known issue that Android Location API doesn’t work in China, because of Chinese government meddling the Google related functions. There is a Github project to provide location functionality in China for react native with AMap (a popular mapping service in China): https://github.com/xiaobuu/react-native-amap-location but it seems to be out of maintenance.

0 Likes

#18

I have the same problem on iOS simulator, when the location on the device was set to None… just set a custom location and it will work

1 Like