-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeoPositionTrackerAnimation
More file actions
149 lines (127 loc) · 3.93 KB
/
GeoPositionTrackerAnimation
File metadata and controls
149 lines (127 loc) · 3.93 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
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
139
140
141
142
143
144
145
146
147
148
149
import React, { useEffect, useMemo, useState, useRef } from 'react';
import { StyleSheet, SafeAreaView, Dimensions, Image, View } from 'react-native';
import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps';
import MapViewDirections from 'react-native-maps-directions';
const GOOGLE_PLACES_API_KEY = 'AIzaSyDj4t6Z_P4Iw8Az0-CrpfJZamqCHrwM950'
const screen = Dimensions.get('window');
const ASPECT_RATIO = screen.width / screen.height;
const LATITUDE_DELTA = 0.04;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
const GeoPositionTracker = ({
coords,
currentDriverPosition,
vendorPosition
}) => {
const marker = useRef()
const map = useRef()
console.log(JSON.stringify(currentDriverPosition, null, 2))
const [coord, setCoord] = useState({
latitude: vendorPosition.latitude,
longitude: vendorPosition.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
});
const [destination, setDestination] = useState({
latitude: coords.latitude,
longitude: coords.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
});
// useEffect(() => {
// map.current.animateToRegion({
// latitude: vendorPosition.latitude,
// longitude: vendorPosition.longitude,
// latitudeDelta: LATITUDE_DELTA,
// longitudeDelta: LONGITUDE_DELTA,
// })
// }, [])
useEffect(() => {
if (currentDriverPosition) {
// setCoord({
// latitude: currentDriverPosition.latitude,
// longitude: currentDriverPosition.longitude,
// latitudeDelta: LATITUDE_DELTA,
// longitudeDelta: LONGITUDE_DELTA,
// });
if (Platform.OS === 'android') {
marker.current.animateMarkerToCoordinate({
latitude: currentDriverPosition.latitude,
longitude: currentDriverPosition.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
})
// map.current.animateToRegion({
// latitude: vendorPosition.latitude,
// longitude: vendorPosition.longitude,
// latitudeDelta: LATITUDE_DELTA,
// longitudeDelta: LONGITUDE_DELTA,
// })
// setCoord({
// latitude: currentDriverPosition.latitude,
// longitude: currentDriverPosition.longitude,
// latitudeDelta: LATITUDE_DELTA,
// longitudeDelta: LONGITUDE_DELTA
// })
} else {
markerOrigin.current.region.timing({
latitude: 38.3368456,
longitude: -122.0299002,
latitudeDelta: 0.0043,
longitudeDelta: 0.0041,
duration: 10000,
}).start()
}
}
}, [currentDriverPosition]);
const Directions = useMemo(() => {
return (
coord && destination && (
<MapViewDirections
origin={coord}
destination={destination}
apikey={GOOGLE_PLACES_API_KEY}
strokeColor="hotpink"
strokeWidth={4}
optimizeWaypoints={true}
/>
)
);
}, [coord, destination]);
return (
<View style={styles.container}>
<MapView provider={PROVIDER_GOOGLE} style={styles.map} initialRegion={coord} ref={map}>
{coord !== undefined && (
<Marker coordinate={coord} ref={marker} />
)}
{destination !== undefined && <Marker coordinate={destination} />}
<MapViewDirections
origin={coord}
destination={destination}
apikey={GOOGLE_PLACES_API_KEY}
strokeColor="hotpink"
strokeWidth={4}
optimizeWaypoints={true}
/>
{/* {Directions} */}
</MapView>
</View>
);
};
const styles = StyleSheet.create({
container: {
height: 200,
width: '100%'
// flex: 1,
},
map: {
...StyleSheet.absoluteFillObject,
zIndex: 0,
},
searchContainer: {
zIndex: 1,
flex: 0.5,
marginHorizontal: 10,
marginVertical: 5,
},
});
export default GeoPositionTracker;