Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curate and collapse GPS location data #35

Merged
merged 1 commit into from
Mar 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions app/views/LocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ import {
} from 'react-native-webview';
import Button from "../components/Button";
import BackgroundGeolocation from '@mauron85/react-native-background-geolocation';


import {
GetStoreData,
SetStoreData
} from '../helpers/General';
import { GetStoreData, SetStoreData } from '../helpers/General';

class LocationTracking extends Component {
constructor(props) {
super(props);
}
componentDidMount() {

BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
Expand Down Expand Up @@ -71,8 +67,22 @@ class LocationTracking extends Component {
locationData = [];
}

locationData.push(location);
SetStoreData('LOCATION_DATA', locationData);
// Curate the list of points
var nowUTC = new Date().toISOString();
var unixtimeUTC = Date.parse(nowUTC);
var unixtimeUTC_28daysAgo = unixtimeUTC - (60 * 60 * 24 * 1000 * 28);

var curated = [];
for (var i = 0; i < locationData.length; i++) {
if (locationData[i]["time"] > unixtimeUTC_28daysAgo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we store the timestamp as well during the location logging

curated.push(locationData[i]);
}
}

var lat_lon_time = { "latitude": location["latitude"], "longitude": location["longitude"], "time": unixtimeUTC };
curated.push(lat_lon_time);

SetStoreData('LOCATION_DATA', curated);
});

// to perform long running operation on iOS
Expand Down Expand Up @@ -108,15 +118,9 @@ class LocationTracking extends Component {
if (status !== BackgroundGeolocation.AUTHORIZED) {
// we need to set delay or otherwise alert may not be shown
setTimeout(() =>
Alert.alert('App requires location tracking permission', 'Would you like to open app settings?', [{
text: 'Yes',
onPress: () => BackgroundGeolocation.showAppSettings()
},
{
text: 'No',
onPress: () => console.log('No Pressed'),
style: 'cancel'
}
Alert.alert('App requires location tracking permission', 'Would you like to open app settings?', [
{ text: 'Yes', onPress: () => BackgroundGeolocation.showAppSettings() },
{ text: 'No', onPress: () => console.log('No Pressed'), style: 'cancel' }
]), 1000);
}
});
Expand Down