-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterialMapView.js
More file actions
76 lines (70 loc) · 2.05 KB
/
MaterialMapView.js
File metadata and controls
76 lines (70 loc) · 2.05 KB
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
import React, { Component, useState, useEffect } from "react";
import { StyleSheet, View } from "react-native";
import MapView, { Marker } from "react-native-maps";
function MaterialMapView(props) {
const [currentLatitude, setLatitude] = useState(0);
const [currentLongitude, setLongitude] = useState(0);
const [locations, setLocations] = useState([]);
useEffect(() => {
navigator.geolocation.getCurrentPosition(node => {
setLatitude(node.coords.latitude);
setLongitude(node.coords.longitude);
fetch(
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + node.coords.latitude + "," + node.coords.longitude + "&type=hospital&radius=50000&key=AIzaSyDByeZVoaaLIG8uLYC5b054XCFHBX6mcts"
)
.then(data => {
return data.json();
})
.then(res =>
setLocations(
res.results.map(marker => (
<Marker
key={marker.name}
coordinate={{
latitude: marker.geometry.location.lat,
longitude: marker.geometry.location.lng
}}
title={marker.name}
></Marker>
))
)
);
}, []);
});
return (
<>
<View style={[styles.container, props.style]}>
<MapView
customMapStyle={["undefined"]}
style={styles.mapView1}
initialRegion={{
latitude: currentLatitude,
longitude: currentLongitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
>
<Marker
coordinate={{
latitude: currentLatitude,
longitude: currentLongitude
}}
title={"My House"}
description={"0 open beds"}
></Marker>
{locations}
</MapView>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: "white"
},
mapView1: {
flex: 1,
backgroundColor: "rgb(230,230,230)"
}
});
export default MaterialMapView;