Created
February 23, 2018 23:02
-
-
Save iwilsonq/9f8abd326264c17927430ef516e918b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... */ | |
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