From 1c8fad936f48ef016a84dec8a6a93b488a5544b9 Mon Sep 17 00:00:00 2001 From: Steve Penrod Date: Sun, 15 Mar 2020 19:30:09 -0500 Subject: [PATCH] Fix to replace code lost during merge #37 (#55) The LocationServices refactor merge lost the changes that happened to adding "curation" to the point data (PR #35). This restores it. --- app/services/LocationService.js | 43 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/app/services/LocationService.js b/app/services/LocationService.js index ca74f29ae1..152c298833 100644 --- a/app/services/LocationService.js +++ b/app/services/LocationService.js @@ -60,10 +60,31 @@ export default class LocationServices { locationData = []; } - locationData.push(location); - console.log('[GPS] Saving point:', locationData.length); + // Curate the list of points + SetStoreData('LOCATION_DATA', locationData); 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]); + } + } - SetStoreData('LOCATION_DATA', locationData); + // Save the location using the current lat-lon and the + // calculated UTC time (maybe a few milliseconds off from + // when the GPS data was collected, but that's unimportant + // for what we are doing.) + console.log('[GPS] Saving point:', locationData.length); + 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 @@ -100,14 +121,14 @@ export default class LocationServices { // 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' - } + text: 'Yes', + onPress: () => BackgroundGeolocation.showAppSettings() + }, + { + text: 'No', + onPress: () => console.log('No Pressed'), + style: 'cancel' + } ]), 1000); } });