have you done any live tracking demo like Uber in react native?
i made one. it's working fine in emulator & simulator with custom location but couldn't get proper location in real device using navigator.geolocation.
watchID = null;
componentDidMount(){
navigator.geolocation.getCurrentPosition((position) => {
let lat = parseFloat(position.coords.latitude);
let long = parseFloat(position.coords.longitude);
let initialRegion = {
latitude : lat,
longitude : long,
latitudeDelta : LATITUDE_DELTA,
longitudeDelta : LONGITUDE_DELTA
}
this.setState({ initialPosition : initialRegion });
this.setState({ markerPostition : initialRegion });
}, (error) => {
alert(JSON.stringify(error))
});
this.watchID = navigator.geolocation.watchPosition((position) => {
let lat = parseFloat(position.coords.latitude);
let long = parseFloat(position.coords.longitude);
let lastRegion = {
latitude : lat,
longitude : long,
latitudeDelta : LATITUDE_DELTA,
longitudeDelta : LONGITUDE_DELTA
}
this.setState({ initialPosition : lastRegion });
this.setState({ markerPostition : lastRegion });
});
}
componentWillUnmount(){
navigator.geolocation.clearWatch(this.watchID);
}
i had set enableHighAccuracy to true but it was throwing error, so, i just removed it. now i'm not getting proper (exact) location of device.
please suggest me Geolocation setup with watchPosition what's worked better for you in case of you made any related project(s).
if you have your code in git repo then i will be thankful of your.
forgive me if i did any grammatical mistakes.