forked from NikValdez/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
95 lines (92 loc) · 2.33 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
import * as React from "react"
import { Dimensions, StyleSheet, Text, View } from "react-native"
import { GooglePlacesAutocomplete } from "react-native-google-places-autocomplete"
import MapView, { Callout, Circle, Marker } from "react-native-maps"
export default function App() {
const [ pin, setPin ] = React.useState({
latitude: 37.78825,
longitude: -122.4324
})
const [ region, setRegion ] = React.useState({
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
})
return (
<View style={{ marginTop: 50, flex: 1 }}>
<GooglePlacesAutocomplete
placeholder="Search"
fetchDetails={true}
GooglePlacesSearchQuery={{
rankby: "distance"
}}
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details)
setRegion({
latitude: details.geometry.location.lat,
longitude: details.geometry.location.lng,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
})
}}
query={{
key: "KEY",
language: "en",
components: "country:us",
types: "establishment",
radius: 30000,
location: `${region.latitude}, ${region.longitude}`
}}
styles={{
container: { flex: 0, position: "absolute", width: "100%", zIndex: 1 },
listView: { backgroundColor: "white" }
}}
/>
<MapView
style={styles.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
provider="google"
>
<Marker coordinate={{ latitude: region.latitude, longitude: region.longitude }} />
<Marker
coordinate={pin}
pinColor="black"
draggable={true}
onDragStart={(e) => {
console.log("Drag start", e.nativeEvent.coordinates)
}}
onDragEnd={(e) => {
setPin({
latitude: e.nativeEvent.coordinate.latitude,
longitude: e.nativeEvent.coordinate.longitude
})
}}
>
<Callout>
<Text>I'm here</Text>
</Callout>
</Marker>
<Circle center={pin} radius={1000} />
</MapView>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
map: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height
}
})