Skip to content

Instantly share code, notes, and snippets.

@iwilsonq
Created February 23, 2018 23:02
Show Gist options
  • Save iwilsonq/9f8abd326264c17927430ef516e918b8 to your computer and use it in GitHub Desktop.
Save iwilsonq/9f8abd326264c17927430ef516e918b8 to your computer and use it in GitHub Desktop.
/* ... */
import { Location, Permissions } from 'expo'
const deltas = {
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
};
export default App extends Component {
state = {
region: null,
coffeeShops: []
};
componentWillMount() {
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({});
const region = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
...deltas
};
await this.setState({ region });
}
render() { /* ... */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment