Reputation: 49
This code only works in Android and Android Emulator, the map shows my exact location, but not in expo iOS simulator, when I use let { status } = await Location.requestPermissionsAsync();
for iOS there is nothing coming back but when I use let { status } = await Permissions.askAsync(Permissions.LOCATION)
a value is returned.
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import MapView from 'react-native-maps';
import * as Location from 'expo-location';
export default class App extends Component {
state = {
location: null,
};
_getLocationAsync = async () => {
// only works in android and android emulator
let { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
console.log('Location permission not granted!');
return;
}
let myLocation = await Location.getCurrentPositionAsync({});
this.setState({ location: myLocation });
};
componentDidMount() {
this._getLocationAsync();
}
render() {
if (!this.state.location) {
return <View />;
}
return (
<MapView
style={{ flex: 1 }}
initialRegion={{
latitude: this.state.location.coords.latitude,
longitude: this.state.location.coords.longitude,
latitudeDelta: 0,
longitudeDelta: 0,
}}
/>
);
}
}
await Location.requestPermissionsAsync()
, but it works perfectly with Android? await Location.getCurrentPositionAsync({});
returns a Promise in Android but nothing in iOS?Upvotes: 1
Views: 4086
Reputation: 365
Be sure that you config correctly location permission on iOS: https://docs.expo.io/versions/latest/sdk/location/#configuration
Upvotes: 1