-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
138 lines (125 loc) · 3.63 KB
/
App.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
import React, { useState, useEffect } from "react";
import { StatusBar, StyleSheet, Text, View, Dimensions } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import MapView, { Marker, Callout } from "react-native-maps";
import * as Location from "expo-location";
import * as Amplitude from "expo-analytics-amplitude";
// all map markers are consolidated in ready JSON data structure:
import kioskit from "./markers/kioskit.json";
const HomeScreen = () => {
const [location, setLocation] = useState({
latitude: 60.169297,
longitude: 24.938435,
latitudeDelta: 0.03,
longitudeDelta: 0.03,
detected: false,
});
useEffect(() => {
Amplitude.initialize("790da95f8f701fd0443d0428315f3c18");
Amplitude.logEvent("APP_OPEN");
});
useEffect(() => {
(async () => {
let { status } = await Location.requestPermissionsAsync();
// if (status !== 'granted') {
// setErrorMsg('Permission to access location was denied');
// }
let newLocation = await Location.getCurrentPositionAsync({});
Amplitude.logEventWithProperties("GET_CURRENT_POSITION", {
latitude: newLocation.coords.latitude,
longitude: newLocation.coords.longitude,
detected: true,
});
setLocation({
latitude: newLocation.coords.latitude,
longitude: newLocation.coords.longitude,
latitudeDelta: 0.03,
longitudeDelta: 0.03,
detected: true,
});
})();
}, []);
return (
<View style={styles.container}>
<StatusBar barStyle="dark-content" />
<MapView
style={styles.mapStyle}
region={location}
showsUserLocation={true}
showsMyLocationButton={true}
>
{kioskit.map((marker) => (
<Marker
key={marker.id}
title={marker.title}
description={marker.description}
coordinate={{
latitude: marker.latitude,
longitude: marker.longitude,
}}
onPress={(event) =>
Amplitude.logEventWithProperties("MARKER_PRESS", {
nativeEvent: event.nativeEvent,
location: location,
})
}
>
<Callout>
<Text style={{ fontWeight: "bold" }}>{marker.title}</Text>
<Text>{marker.description}</Text>
</Callout>
</Marker>
))}
</MapView>
</View>
);
};
const Stack = createStackNavigator();
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator
/*screenOptions={{
headerStyle: {
backgroundColor: "#dddddd",
},
headerTintColor: "#222244",
headerTitleStyle: {
fontWeight: "bold",
},
}} */
>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: "Jäätelökioskit",
//headerStyle: {
// backgroundColor: "#281e78",
//},
// headerTintColor: "#f2efd9",
headerTitleStyle: {
fontWeight: "bold",
// fontFamily: "Copperplate",
fontSize: 21,
},
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
// backgroundColor: "#281E78",
alignItems: "center",
justifyContent: "center",
},
mapStyle: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
},
});
export default App;