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:
parent
924dd47395
commit
11c2a1713f
|
@ -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,27 +65,39 @@ const GpxRecord: React.FC<{}> = () => {
|
|||
const dispatch = useDispatch();
|
||||
|
||||
const newLocationHandler = (location: any) => {
|
||||
appendTrkpt(db, {
|
||||
$: {
|
||||
lat: location.latitude,
|
||||
lon: location.longitude,
|
||||
},
|
||||
ele: location.altitude,
|
||||
time: new Date(location.time).toISOString(),
|
||||
extensions: {
|
||||
speed: location.speed,
|
||||
accuracy: location.accuracy,
|
||||
},
|
||||
});
|
||||
dispatch(
|
||||
mapActions.setCurrent({
|
||||
lat: location.latitude,
|
||||
lon: location.longitude,
|
||||
})
|
||||
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,
|
||||
lon: location.longitude,
|
||||
},
|
||||
ele: location.altitude,
|
||||
time: new Date(location.time).toISOString(),
|
||||
extensions: {
|
||||
speed: location.speed,
|
||||
accuracy: location.accuracy,
|
||||
},
|
||||
});
|
||||
dispatch(
|
||||
mapActions.setCurrent({
|
||||
lat: location.latitude,
|
||||
lon: location.longitude,
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const startRecording = () => {
|
||||
globalThis.$lastValidLocationTime = 0;
|
||||
startBackgroundGeolocation(newLocationHandler).then((result) => {
|
||||
setWatcher_id(result);
|
||||
});
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue