Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions content/wardrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,22 @@ async function releaseWakeLock() {

// ---- Geolocation ----
async function getCurrentPosition() {
if (DEBUG_GPS_LOGGING) {
console.log("[GPS] Requesting current position");
}

return new Promise((resolve, reject) => {
if (!("geolocation" in navigator)) {
reject(new Error("Geolocation not supported"));
return;
}
navigator.geolocation.getCurrentPosition(
(pos) => resolve(pos),
(pos) => {
if (DEBUG_GPS_LOGGING) {
console.log(`[GPS] Got current position: ${pos.coords.latitude.toFixed(5)}, ${pos.coords.longitude.toFixed(5)}, accuracy: ±${Math.round(pos.coords.accuracy)}m`);
}
resolve(pos);
},
(err) => reject(err),
{
enableHighAccuracy: true,
Expand Down Expand Up @@ -406,6 +415,7 @@ function startGpsAgeUpdater() {
if (state.gpsAgeUpdateTimer) return;
state.gpsAgeUpdateTimer = setInterval(() => {
updateGpsUi();
updateDistanceDisplay(); // Also update distance from last ping
}, 1000); // Update every second
}

Expand All @@ -420,6 +430,10 @@ function startGeoWatch() {
if (state.geoWatchId) return;
if (!("geolocation" in navigator)) return;

if (DEBUG_GPS_LOGGING) {
console.log("[GPS] Starting continuous GPS watch");
}

state.gpsState = "acquiring";
updateGpsUi();
startGpsAgeUpdater(); // Start the age counter
Expand All @@ -433,7 +447,13 @@ function startGeoWatch() {
tsMs: Date.now(),
};
state.gpsState = "acquired";

if (DEBUG_GPS_LOGGING) {
console.log(`[GPS] Position updated: ${pos.coords.latitude.toFixed(5)}, ${pos.coords.longitude.toFixed(5)}, accuracy: ±${Math.round(pos.coords.accuracy)}m`);
}

updateGpsUi();
updateDistanceDisplay(); // Update distance when GPS position updates
},
(err) => {
console.warn("watchPosition error:", err);
Expand Down Expand Up @@ -609,8 +629,10 @@ async function sendPing(manual = false) {
// Auto mode: use GPS watch data
if (!state.lastFix) {
// If no GPS fix yet in auto mode, skip this ping and wait for watch to acquire location
console.warn("Auto ping skipped: waiting for GPS fix");
setStatus("Waiting for GPS fix...", "text-amber-300");
if (DEBUG_GPS_LOGGING) {
console.warn("[GPS] Auto ping skipped: waiting for GPS fix");
}
handlePingSkip("Waiting for GPS fix...", manual);
return;
}
lat = state.lastFix.lat;
Expand Down
Loading