Firstattempt to reduce te number of points when recording a track (#13): the minimal distance is now 10m and a filter with a minimal time of 15s has been added.

This should now be tested on the road !
This commit is contained in:
Eric van der Vlist 2022-10-02 21:52:02 +02:00
parent 924dd47395
commit 11c2a1713f
2 changed files with 37 additions and 19 deletions

View File

@ -1,4 +1,4 @@
import React, { Fragment, useRef, useState } from 'react';
import React, { Fragment, useEffect, useRef, useState } from 'react';
import { useDB, useFind } from 'react-pouchdb';
@ -28,6 +28,12 @@ import { enterAnimation, leaveAnimation } from '../../lib/animation';
import { useDispatch } from 'react-redux';
import { mapActions } from '../../store/map';
const MIN_TIME_BETWEEN_LOCATIONS = 15 * 1000;
declare global {
var $lastValidLocationTime: number;
}
const GpxRecord: React.FC<{}> = () => {
const db = useDB();
@ -59,6 +65,16 @@ const GpxRecord: React.FC<{}> = () => {
const dispatch = useDispatch();
const newLocationHandler = (location: any) => {
console.log(
`Location filtering, elapsed time: ${
location.time - globalThis.$lastValidLocationTime
}`
);
if (
location.time - globalThis.$lastValidLocationTime >
MIN_TIME_BETWEEN_LOCATIONS
) {
globalThis.$lastValidLocationTime = location.time;
appendTrkpt(db, {
$: {
lat: location.latitude,
@ -77,9 +93,11 @@ const GpxRecord: React.FC<{}> = () => {
lon: location.longitude,
})
);
}
};
const startRecording = () => {
globalThis.$lastValidLocationTime = 0;
startBackgroundGeolocation(newLocationHandler).then((result) => {
setWatcher_id(result);
});

View File

@ -31,7 +31,7 @@ const backgroundGeolocationConfig = {
// The minimum number of metres between subsequent locations. Defaults
// to 0.
distanceFilter: 5,
distanceFilter: 10,
};
export const startBackgroundGeolocation = async (newLocationHandler: any) => {