-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
61 lines (53 loc) · 1.61 KB
/
Home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, {Component} from 'react';
import Geolocation from '@react-native-community/geolocation';
import SlidingUpPanel from 'rn-sliding-up-panel';
import Map from './Map.js';
import HomeV2 from './HomeV2.js'
import { PermissionsAndroid, Platform } from 'react-native'
export default class Home extends Component{
constructor(props) {
super(props);
this.updateLocation = this.updateLocation.bind(this)
this.requestLocationPermissionAndroid = this.requestLocationPermissionAndroid.bind(this)
this.state = {};
if(Platform.OS === 'android') {
this.requestLocationPermissionAndroid();
}
else {
this.updateLocation();
}
}
updateLocation = () => {
Geolocation.getCurrentPosition(location => this.setState({ location }));
}
async requestLocationPermissionAndroid() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Berkeley Mobile Location Permission',
message:
'Berkeley Mobile would like to access your location.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
this.updateLocation()
} else {
console.log('Permission denied');
}
} catch (err) {
console.warn(err);
}
}
render() {
return (
<>
<Map location = {this.state.location ? this.state.location.coords : {longitude: -122.2578, latitude: 37.8721}}/>
<HomeV2 />
</>
);
}
}