How to use the react-native-background-geolocation.watchPosition function in react-native-background-geolocation

To help you get started, weโ€™ve selected a few react-native-background-geolocation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devnowcafe / runx / src / screens / Home / index.js View on Github external
switch (state) {
                case 'running':
                    runState = { ...this.state.runState, state: 'running', runAt: new Date() };
                    BackgroundGeolocation.start();
                    this._interval = setInterval(() => {
                        this.setState({ runningDuration: this.state.runningDuration + 1 })
                    }, 1000);
                    break;
                case 'paused':
                    runState = { ...this.state.runState, state: 'paused', pauseAt: new Date() };
                    clearInterval(this._interval);
                    BackgroundGeolocation.stopWatchPosition();
                    break;
                case 'resume':
                    runState = { ...this.state.runState, state: 'running' };
                    BackgroundGeolocation.watchPosition();
                    this._interval = setInterval(() => {
                        this.setState({ runningDuration: this.state.runningDuration + 1 })
                    }, 1000);
                    break;
                case 'finished':
                    runState = { ...this.state.runState, state: 'finished', finishAt: new Date() };
                    clearInterval(this._interval);
                    BackgroundGeolocation.stop();
                    break;
            }
            await AsyncStorage.setItem(`${Configs.StorageKey}:runstate`, JSON.stringify(runState, null));

            this.setState({ runState })
        }
    }