expo: Location not working on Android 6
Trying the exact same code from the documentation: https://docs.expo.io/versions/v19.0.0/sdk/location.html
await Location.getCurrentPositionAsync({}); is waiting forever, all location options on phone active (GPS, Wifi, cellular). Tried in Genymotion with gapps (I removed the check from the code for this) and a real phone (Le 2). I’m using the latest xde and expo app (updated today: July 26th, 2017).
Working perfectly on Android 5.1.
import React, { Component } from 'react';
import { Platform, Text, View, StyleSheet } from 'react-native';
import { Constants, Location, Permissions } from 'expo';
export default class App extends Component {
state = {
location: null,
errorMessage: null,
};
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 () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied',
});
}
let location = await Location.getCurrentPositionAsync({});
this.setState({ location });
};
render() {
let text = 'Waiting..';
if (this.state.errorMessage) {
text = this.state.errorMessage;
} else if (this.state.location) {
text = JSON.stringify(this.state.location);
}
return (
<View style={styles.container}>
<Text style={styles.paragraph}>{text}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
paragraph: {
margin: 24,
fontSize: 18,
textAlign: 'center',
},
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (8 by maintainers)
Commits related to this issue
- Fix typo `permission` in docs (#426) * Update configuration.md * Update UNVERSIONED-schema.json * Update 19.0.0-schema.json — committed to expo/expo by satya164 7 years ago
Hello, all I’m trying to debug this - what I came across is that if you have location mode set (in system settings) set to GPS only location won’t be gathered (not sure if at all or for example in buildings? that’s where I am testing). What’s more, even Google Maps app won’t show your location. Setting this to High accuracy or Battery saving everything works.
I’d appreciate any feedback if this works for you as well.
@myztajay If you’re using create react native app and have not detached or ejected from expo, it shouldn’t be possible for you to edit your AndroidManifest.xml. Are you attempting to build a standalone version? You have to include the permission in app.json.