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';
|
import { useDB, useFind } from 'react-pouchdb';
|
||||||
|
|
||||||
|
@ -28,6 +28,12 @@ import { enterAnimation, leaveAnimation } from '../../lib/animation';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { mapActions } from '../../store/map';
|
import { mapActions } from '../../store/map';
|
||||||
|
|
||||||
|
const MIN_TIME_BETWEEN_LOCATIONS = 15 * 1000;
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
var $lastValidLocationTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
const GpxRecord: React.FC<{}> = () => {
|
const GpxRecord: React.FC<{}> = () => {
|
||||||
const db = useDB();
|
const db = useDB();
|
||||||
|
|
||||||
|
@ -59,6 +65,16 @@ const GpxRecord: React.FC<{}> = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const newLocationHandler = (location: any) => {
|
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, {
|
appendTrkpt(db, {
|
||||||
$: {
|
$: {
|
||||||
lat: location.latitude,
|
lat: location.latitude,
|
||||||
|
@ -77,9 +93,11 @@ const GpxRecord: React.FC<{}> = () => {
|
||||||
lon: location.longitude,
|
lon: location.longitude,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const startRecording = () => {
|
const startRecording = () => {
|
||||||
|
globalThis.$lastValidLocationTime = 0;
|
||||||
startBackgroundGeolocation(newLocationHandler).then((result) => {
|
startBackgroundGeolocation(newLocationHandler).then((result) => {
|
||||||
setWatcher_id(result);
|
setWatcher_id(result);
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,7 +31,7 @@ const backgroundGeolocationConfig = {
|
||||||
|
|
||||||
// The minimum number of metres between subsequent locations. Defaults
|
// The minimum number of metres between subsequent locations. Defaults
|
||||||
// to 0.
|
// to 0.
|
||||||
distanceFilter: 5,
|
distanceFilter: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const startBackgroundGeolocation = async (newLocationHandler: any) => {
|
export const startBackgroundGeolocation = async (newLocationHandler: any) => {
|
||||||
|
|
Loading…
Reference in New Issue