-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
112 lines (110 loc) · 3.25 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
import axios from "axios";
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import { StyleSheet, View, Text, Image } from "react-native";
import MapView, {
Marker,
PROVIDER_GOOGLE,
Polygon,
Callout,
Circle,
} from "react-native-maps";
export default function App() {
const [events, setEvents] = useState([]);
useEffect(() => {
axios
.get("https://api.plurppl.com/api/events", {
headers: {
Accept: "*/*",
Authorization:
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImFhNWI4MmE4LTE4NzktNDhiMS05NmY1LWY5MTAwMDVkNjE4NCIsInBpZCI6IlBMMTY4MzAzMTYwNjAwMCIsIm5hbWUiOiJzYWFkIDMxMDYwODk3NjAiLCJlbWFpbCI6InNhYWRxYWRpcjc4NkBnbWFpbC5jb20iLCJwaG9uZSI6IjMxMDYwODk3NjAiLCJyb2xlIjoiU3RhbmRhcmQiLCJpYXQiOjE2OTAxNzg1NTJ9.AEV6dACdH5yWK5iVpr7JQcQYUzM1tPZ-WuD3q-NAWZI",
},
})
.then((res) => {
if (res.status === 200) {
setEvents(res.data.slice(1, 50));
}
})
.catch((err) => console.log(err));
}, []);
return (
<View style={styles.container}>
<StatusBar style="auto" />
{events.length > 0 ? (
<MapView
style={styles.map}
provider={PROVIDER_GOOGLE}
minZoomLevel={5}
initialRegion={{
latitude: 30.269544,
longitude: -97.745284,
longitudeDelta: 0.0421,
latitudeDelta: 0.0922,
}}
initialCamera={{
latitude: 30.269544,
longitude: -97.745284,
}}
>
<Polygon
coordinates={[
{ longitude: -97.721751, latitude: 30.301187 },
{ longitude: -97.895092, latitude: 30.25067 },
{ longitude: -97.740802, latitude: 30.160229 },
]}
strokeWidth={1}
fillColor="rgba(90,34,139,0.2)"
strokeColor="rgba(90,34,139,1)"
tappable={true}
/>
<Circle
center={{ latitude: 30.269544, longitude: -97.745284 }}
radius={5000}
strokeColor="orange"
fillColor="rgba(211,84,0,1)"
/>
{events?.map((event) => {
if (event?.latitude > 90 || event?.latitude < -90) {
return null;
}
return (
<Marker
key={event?.id}
coordinate={{
latitude: Number(event?.latitude),
longitude: Number(event?.longitude),
}}
pinColor="red"
>
<Callout
children={
<View>
<Text style={{ textAlign: "center" }}>{event.name}</Text>
<Text style={{ textAlign: "center" }}>
Category: {event.category}
</Text>
</View>
}
/>
</Marker>
);
})}
</MapView>
) : (
<Text>Loading events...</Text>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
map: {
width: "100%",
height: "100%",
},
});