mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-12-03 09:44:08 +00:00
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.
25 lines
966 B
JavaScript
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; }
|
|
}
|