Persist GPS coords in sessionStorage; fall back to raw coords on geocode failure

iOS Safari can discard page JS state when backgrounding to open the camera.
Saving gpsCoords to sessionStorage ensures the coords survive the round-trip
and are still available when handleUpload runs after the photo is taken.

Also change the server-side geocode fallback from empty string to raw lat/lon
so the location column in the Excel sheet is never silently empty.

https://claude.ai/code/session_015myTTMs6yDsAGarATe5ePZ
This commit is contained in:
Claude 2026-03-18 20:36:32 +00:00
parent eeeb380686
commit 0431308cb4
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View file

@ -133,7 +133,7 @@ async fn upload(
let location = if let (Some(la), Some(lo)) = (lat, lon) { let location = if let (Some(la), Some(lo)) = (lat, lon) {
geocode::reverse_geocode(la, lo) geocode::reverse_geocode(la, lo)
.await .await
.unwrap_or_default() .unwrap_or_else(|_| format!("{:.5}, {:.5}", la, lo))
} else { } else {
String::new() String::new()
}; };

View file

@ -156,7 +156,10 @@
</div> </div>
<script> <script>
let gpsCoords = null; // Restore coords if iOS discarded the page while camera was open
let gpsCoords = (() => {
try { return JSON.parse(sessionStorage.getItem('gpsCoords')); } catch { return null; }
})();
function getLocation() { function getLocation() {
const el = document.getElementById('loc-status'); const el = document.getElementById('loc-status');
@ -168,6 +171,7 @@
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
pos => { pos => {
gpsCoords = { lat: pos.coords.latitude, lon: pos.coords.longitude }; gpsCoords = { lat: pos.coords.latitude, lon: pos.coords.longitude };
sessionStorage.setItem('gpsCoords', JSON.stringify(gpsCoords));
el.innerHTML = '<span style="color:#388e3c">📍 Location captured</span>'; el.innerHTML = '<span style="color:#388e3c">📍 Location captured</span>';
}, },
err => { err => {
@ -328,6 +332,7 @@
async function startOver() { async function startOver() {
await fetch('/reset', { method: 'POST' }); await fetch('/reset', { method: 'POST' });
gpsCoords = null; gpsCoords = null;
sessionStorage.removeItem('gpsCoords');
showStep(1); showStep(1);
} }