From 20159a8c8e37a4e47f4f9518dc4b146229e9a69e Mon Sep 17 00:00:00 2001 From: Steve Penrod Date: Fri, 13 Mar 2020 22:19:13 -0500 Subject: [PATCH] Curate and collapse GPS location data (#35) This changes several things about the data being stored: * The time being stored in the structure is now UTC. It was previous local time * The data being stored is now simplified to: [ (utc_unix_time, GPS lat, GPS lon) ... ] * The stored data is now limited to 28 days --- app/views/LocationTracking.js | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/app/views/LocationTracking.js b/app/views/LocationTracking.js index 8d28406dd4..7d83ede659 100644 --- a/app/views/LocationTracking.js +++ b/app/views/LocationTracking.js @@ -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, @@ -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) { + 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 @@ -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); } });