'How to get GPS location in react-native-maps
My react-native app is using react-native-maps to display a Google Maps and a marker. A styled View is used as the location marker that has a fixed position on the device screen.
Question: How can we get the GPS coordinates (lat/lng) of the marker, at say the bottom left corner of the <View style={styles.marker}> component?
<MapView
ref='map'
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
showsUserLocation={true}
></MapView>
<View style={styles.markerContainer}>
<View style={styles.marker}>
</View>
</View>
styles
var deviceHeight = Dimensions.get('window').height;
StyleSheet.create({
markerContainer: {
bottom: deviceHeight/2.2,
position: 'absolute',
left: 0,
right: 0,
},
})
Solution 1:[1]
<MapView
ref='map'
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
showsUserLocation={true}
**onUserLocationChange={(e)=>console.log(e.nativeEvent.coordinate)}**
></MapView>
<View style={styles.markerContainer}>
<View style={styles.marker}>
</View>
</View>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
