From 8713169e84d5d67492189baf8d68a1af7fc28910 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sun, 31 May 2026 09:53:23 -0400 Subject: [PATCH] feat: add My GPS button to asset detail GPS editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a '📍 My GPS' button to the GPS Map Editor card in the asset detail screen that: - Grabs device GPS via navigator.geolocation.getCurrentPosition - Places map marker at current device position - Auto-unlocks the GPS editor if locked, shows Save button - Displays accuracy in status text - Provides clear error messages for denied/timed-out/unavailable Includes enableHighAccuracy: true, 15s timeout, 60s cache. --- static/index.html | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/static/index.html b/static/index.html index fbc3be2..4e89442 100644 --- a/static/index.html +++ b/static/index.html @@ -1303,6 +1303,7 @@
+ @@ -4280,6 +4281,69 @@ } } + async function getCurrentGps() { + // Check browser geolocation support + if (!navigator.geolocation) { + showToast('GPS not supported on this device', true); + return; + } + + const myGpsBtn = document.getElementById('detailGpsMyGpsBtn'); + myGpsBtn.textContent = '⏳ Getting GPS...'; + myGpsBtn.disabled = true; + + navigator.geolocation.getCurrentPosition( + function(pos) { + const lat = Math.round(pos.coords.latitude * 1000000) / 1000000; + const lng = Math.round(pos.coords.longitude * 1000000) / 1000000; + + // Update the marker on the GPS editor map + if (_gpsState.marker) { + _gpsState.marker.setLatLng([lat, lng]); + } else { + showToast('GPS map not initialized yet', true); + myGpsBtn.textContent = '📍 My GPS'; + myGpsBtn.disabled = false; + return; + } + + // Update coords display + document.getElementById('detailGpsCoords').textContent = + `${lat.toFixed(6)}, ${lng.toFixed(6)}`; + + // Auto-unlock if currently locked + if (!_gpsState.unlocked) { + toggleGpsLock(); + } + + // Show save button and update status/info + document.getElementById('detailGpsSaveBtn').style.display = ''; + document.getElementById('detailGpsStatus').textContent = + `📍 Device GPS (accuracy: ${Math.round(pos.coords.accuracy)}m)`; + + showToast(`📍 GPS position set: ${lat}, ${lng}`, false); + + myGpsBtn.textContent = '📍 My GPS'; + myGpsBtn.disabled = false; + }, + function(err) { + const msgs = { + 1: 'GPS permission denied — allow location access in your browser settings', + 2: 'GPS position unavailable — try moving to an open area', + 3: 'GPS request timed out — try again', + }; + showToast('GPS error: ' + (msgs[err.code] || err.message), true); + myGpsBtn.textContent = '📍 My GPS'; + myGpsBtn.disabled = false; + }, + { + enableHighAccuracy: true, + timeout: 15000, + maximumAge: 60000, + } + ); + } + function statusBadge(status) { return ''; }