I want to keep track of the location of user using watchposition in react native and send that location to server is it possible?
2 Answers
I would recommend you to use this https://github.com/mauron85/react-native-background-geolocation its pretty simple to use.
Comments
I have used this plugin react-native-background-timer to enable my app to run in background as well and get device location here is the sample code
BackgroundTimer.setInterval(() => {
navigator.geolocation.getCurrentPosition((position) => {
this.setState({
startDrive: true,
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
this.offlineHistoryManager(position.coords.latitude, position.coords.longitude);
}, (error) => {
LocationSwitch.enableLocationService(1000, true, () => { //
}, () => { //
},);
}, {enableHighAccuracy: false, timeout: 20000});
}, 30000);