Created
July 13, 2017 05:28
-
-
Save reggie3/3cb696d295b67321d3fa61ee83df830b to your computer and use it in GitHub Desktop.
Calling location periodically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentWillMount() { | |
... | |
// periodically check device location and write the results to | |
// the location markers | |
setInterval( | |
this.performLocationChecking.bind(this), | |
1000); | |
} | |
performLocationChecking() { | |
if (this.props.appState.currentLocation.coords.latitude) { | |
let currentLoc = this.props.appState.currentLocation.coords; | |
// for each location marker, perform work in its reducer that stores the distance | |
// from the device to the location | |
this.props.locations.forEach((location) => { | |
this.props.dispatch(actions.locationsActions.writeDistanceResults( | |
location.ID, | |
geolib.getDistance( | |
{ latitude: currentLoc.latitude, longitude: currentLoc.longitude }, | |
{ latitude: location.loc[0], longitude: location.loc[1] }, | |
this.props.config.distanceCheckAccuracy, | |
this.props.config.distanceCheckPrecision | |
), | |
this.props.config.locationSensitivityDamping | |
)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment