Skip to content

Instantly share code, notes, and snippets.

@reggie3
Created July 13, 2017 05:28
Show Gist options
  • Save reggie3/3cb696d295b67321d3fa61ee83df830b to your computer and use it in GitHub Desktop.
Save reggie3/3cb696d295b67321d3fa61ee83df830b to your computer and use it in GitHub Desktop.
Calling location periodically
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