1

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 2

1

I would recommend you to use this https://github.com/mauron85/react-native-background-geolocation its pretty simple to use.

Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.