Files
corescope-rx/src/gps.js
T
efiten 91bbe1a67f fix(app): live GPS marker/follow updates continuously, not only on RX
The map's position marker only moved when a packet arrived, so it appeared to
hang and jump. GPS fixes (watchPosition) now feed the map directly via
setPosition; hexes are still added only on a real RX.
2026-06-10 16:37:22 +02:00

25 lines
966 B
JavaScript

// Phone GPS. Each reception is tagged with the latest fix; no fix → no row
// (coverage without a position is useless).
export class Gps {
constructor() { this._last = null; this._watchId = null; }
// start(onFix): begins watching; onFix (optional) fires on every position
// update so the UI can track GPS continuously, independent of RX packets.
start(onFix) {
if (!navigator.geolocation) throw new Error('geolocation unavailable');
this._watchId = navigator.geolocation.watchPosition(
(p) => {
this._last = { lat: p.coords.latitude, lon: p.coords.longitude, acc_m: p.coords.accuracy };
if (onFix) onFix(this._last);
},
() => {},
{ enableHighAccuracy: true, maximumAge: 5000, timeout: 15000 }
);
}
stop() { if (this._watchId != null) navigator.geolocation.clearWatch(this._watchId); this._watchId = null; }
// latest() returns the most recent fix or null.
latest() { return this._last; }
}