Hey guys i have created a mapView in react-native now i have to set fix marker on user current location. I have obtained current location using navigator.geolocation also set the marker using MapView.Marker initially marker shows correct location but gets moved on zooming and pinching
Here is my code.
getInitialState() {
return {
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
},
};
},
componentDidMount: function() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
region: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
}
});
},
);
this.watchID = navigator.geolocation.watchPosition((position) => {
const newRegion = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
}
this.onRegionChange(newRegion);
});
},
here is the render method
render() {
return (
<View style={styles.container}>
<MapView
ref="map"
style={styles.map}
region={this.state.region}
onRegionChange={this.onRegionChange}
>
<MapView.Marker coordinate={this.state.region}>
</MapView.Marker>
</MapView>
can anybody help on this? Thanks in advance