Skip to content

Commit

Permalink
Curate and collapse GPS location data (#35)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
penrods committed Mar 14, 2020
1 parent b77bf1c commit 20159a8
Showing 1 changed file with 21 additions and 17 deletions.
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) {
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

0 comments on commit 20159a8

Please sign in to comment.