-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map.js
134 lines (106 loc) · 2.77 KB
/
Map.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
import React from 'react';
import { View, Text, Button, AsyncStorage, StyleSheet, TouchableWithoutFeedback } from 'react-native'
import MapView from 'react-native-maps';
export default class Map extends React.Component {
static navigationOptions = {
title: 'Map',
};
constructor(props) {
super(props);
this.state = {
movieUrl: null
}
// TODO: Save movie list from App.js and just reference from there
AsyncStorage.getAllKeys((err, keys) => {
AsyncStorage.multiGet(keys, (err, stores) => {
let compareFunction = function compare(a, b) {
let aObject = JSON.parse(a[1])
let bObject = JSON.parse(b[1])
if (aObject.timestamp < bObject.timestamp) {
return -1;
}
if (aObject.timestamp > bObject.timestamp) {
return 1;
}
// a must be equal to b
return 0;
}
let movies = stores.sort(compareFunction)
// TODO: Probably more efficient way to do this
let sortedMovies = [];
for (let i = 0; i < movies.length; i++) {
sortedMovies.push(JSON.parse(movies[i][1]))
}
console.log("movies... " , stores);
this.setState({
keys: keys,
movieIndex: 0,
movies: sortedMovies
})
});
});
}
render() {
const { navigate } = this.props.navigation;
let loadedMovies = this.state.movies || []
// Could prob do this in same step with .reduce
loadedMovies = loadedMovies.filter((movie) => {
console.log("before movie " , movie);
if (!movie.timestamp) {
return false
} else {
return movie
}
})
const markers = loadedMovies.map((movie) => {
console.log("movie " , movie);
let latlng = {
latitude: movie.location.lat,
longitude: movie.location.lng
}
let time = movie.timestamp.toString()
return <MapView.Marker
key={time}
coordinate={latlng}
onPress={() => {
console.log("hey " , movie.path);
}}
/>
})
console.log("markers " , markers);
return (
<View style={styles.container}>
<MapView
style={styles.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 1,
longitudeDelta: 1,
}}
>
{markers}
</MapView>
</View>
);
}
}
// Later on in your styles..
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
},
});