-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapScreen.js
170 lines (145 loc) · 4.17 KB
/
MapScreen.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { Component } from 'react';
import { StyleSheet, Text, View, Vibration, PermissionsAndroid, TouchableOpacity } from 'react-native';
import MapView, { Animated, Marker } from 'react-native-maps';
import Video from 'react-native-video';
const LATITUDE_DELTA = 0.0922
const LONGITUDE_DELTA = 0.0421
export default class MapScreen extends React.Component {
static navigationOptions = {
title: 'Alarm',
};
video: Video;
async requestLocationPermission() {
try {
var granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Location Permission',
'message': 'Location Alarm needs access to your location (who\'da thunk it?)'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the location")
} else {
console.log("Location permission denied")
}
} catch (err) {
console.warn(err)
}
}
constructor() {
super();
this.state = {
region: {
latitude: 42.3601,
longitude: -71.0589,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
},
marker: {
latitude: 42.3601,
longitude: -71.0589
},
sound: {
rate: 1,
volume: 1,
muted: false,
resizeMode: 'contain',
duration: 0.0,
currentTime: 0.0,
paused: true,
}
};
}
getCurrentLocation() {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(position => resolve(position), e => reject(e));
});
};
componentDidMount() {
this.requestLocationPermission();
navigator.geolocation.watchPosition(event => this.onUserLocationChange(event));
}
onRegionChange(region) {
this.setState({ region: region });
}
onUserLocationChange(event) {
this.setState({user: event.coords});
let diffLat = event.coords.latitude - this.state.marker.latitude;
let diffLong = event.coords.longitude - this.state.marker.longitude;
if (Math.abs(diffLat) < 0.0025 && Math.abs(diffLong) < 0.0025) {
console.log(diffLat);
Vibration.vibrate(1000);
this.video.seek(0);
this.setState({sound: {paused: !this.state.sound.paused}});
};
}
onPress(event) {
this.setState({marker: event.nativeEvent.coordinate});
}
setMarkerLocation(latitude, longitude) {
this.setState({marker: {latitude: latitude, longitude: longitude}});
}
render() {
const {navigation} = this.props;
return (
<View style={styles.container}>
<MapView style={styles.map}
provider={'google'}
showsUserLocation={true}
initialRegion={this.state.region}
onPress={ event => this.onPress(event) }
showsCompass={true}
>
<MapView.Marker
coordinate={this.state.marker}
/>
</MapView>
<TouchableOpacity style={styles.overlay} onPress={() => this.props.navigation.navigate('AddressScreen', {setMarkerLocation: this.setMarkerLocation.bind(this)})}>
<Text style={styles.buttonText}>YA LOST DUMBASS?</Text>
</TouchableOpacity>
<Video
source={require('./assets/sounds/Roland-JV-2080-Pick-Bass-C2.wav')}
ref = {(ref) => {this.video = ref}}
paused={this.state.sound.paused}
volume={this.state.sound.volume}
muted={this.state.sound.muted}
repeat={true}
>
</Video>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
},
map: {
height: '100%',
width: '100%'
},
textInput: {
position:'absolute',
borderWidth: 10
},
backgroundVideo: {
height: 0,
width: 0
},
overlay: {
alignItems: 'center',
position: 'absolute',
top: 50,
padding: 10,
backgroundColor: 'rgba(237,45,255,.5)',
borderRadius: 10,
borderWidth: 1
},
buttonText: {
fontWeight: 'bold',
fontSize: 20,
fontStyle: 'italic'
}
});