-
Notifications
You must be signed in to change notification settings - Fork 0
/
understand.tsx
108 lines (97 loc) · 2.59 KB
/
understand.tsx
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
import React, { useEffect, useState } from "react";
import { Dimensions, StyleSheet, View } from "react-native";
import MapView, { Marker, Region } from "react-native-maps";
function getRandomLatitude(min = 48, max = 56) {
return Math.random() * (max - min) + min;
}
function getRandomLongitude(min = 14, max = 24) {
return Math.random() * (max - min) + min;
}
interface Markers {
id: number;
latitude: number;
longitude: number;
}
function App(): JSX.Element {
const [zoom, setZoom] = useState(18);
const [markers, setMarkers] = useState<Markers[]>([
{ id: 0, latitude: 53.91326738786109, longitude: 27.523712915343737 },
]);
const region: Region = {
latitude: 53.91326738786109,
longitude: 27.523712915343737,
latitudeDelta: 0.1,
longitudeDelta: 0.1,
};
const map = React.useRef(null);
const generateMarkers = React.useCallback((lat: number, long: number) => {
const markersArray = [];
for (let i = 0; i < 50; i++) {
markersArray.push({
id: i,
latitude: getRandomLatitude(lat - 0.05, lat + 0.05),
longitude: getRandomLongitude(long - 0.05, long + 0.05),
});
}
setMarkers(markersArray);
}, []);
useEffect(() => {
generateMarkers(region.latitude, region.longitude);
}, []);
const getRegionForZoom = (lat: number, lon: number, zoom: number) => {
const distanceDelta = Math.exp(Math.log(360) - zoom * Math.LN2);
const { width, height } = Dimensions.get("window");
const aspectRatio = width / height;
return {
latitude: lat,
longitude: lon,
latitudeDelta: distanceDelta * aspectRatio,
longitudeDelta: distanceDelta,
};
};
return (
<View style={styles.container}>
<MapView
ref={map}
mapType="hybrid"
style={styles.mapView}
initialRegion={region}
>
{markers.map((item) => (
<Marker
key={item.id}
coordinate={{
latitude: item.latitude,
longitude: item.longitude,
}}
></Marker>
))}
</MapView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
mapView: { flex: 1, width: "100%", height: "100%" },
});
export default App;
const dbRef = firebase.database().ref();
dbRef
.child("users")
.child(userId)
.get()
.then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
})
.catch((error) => {
console.error(error);
});