Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hasLocationPermission = () => {
- try{
- const granted = PermissionsAndroid.request(
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
- {
- title: 'Location Permission',
- message: 'You must to accept this to make it work.'
- }
- )
- if(granted === PermissionsAndroid.RESULTS.GRANTED){
- console.log('Location permission accepted.')
- }else{
- console.log("Location permission denied")
- }
- } catch (err) {
- console.warn(err)
- }
- }
- getUserLocationHandler = () => {
- if(this.hasLocationPermission){
- Geolocation.getCurrentPosition(
- position => {
- this.setState({
- userLocation: {
- latitude: position.coords.latitude,
- longitude: position.coords.longitude,
- latitudeDelta: 0.0622,
- longitudeDelta: 0.0421,
- },
- });
- },
- err => console.log(err),
- {
- enableHighAccuracy: true,
- timeout: 15000,
- maximumAge: 10000
- }
- );
- }
- }
- render() {
- return (
- <View style={styles.container}>
- <FetchLocation onGetLocation={this.getUserLocationHandler}/>
- <UsersMap userLocation={this.state.userLocation}/>
- </View>
- );
- }
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Add Comment
Please, Sign In to add comment