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:
parent
eeeb380686
commit
0431308cb4
2 changed files with 7 additions and 2 deletions
|
|
@ -133,7 +133,7 @@ async fn upload(
|
|||
let location = if let (Some(la), Some(lo)) = (lat, lon) {
|
||||
geocode::reverse_geocode(la, lo)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_else(|_| format!("{:.5}, {:.5}", la, lo))
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -156,7 +156,10 @@
|
|||
</div>
|
||||
|
||||
<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() {
|
||||
const el = document.getElementById('loc-status');
|
||||
|
|
@ -168,6 +171,7 @@
|
|||
navigator.geolocation.getCurrentPosition(
|
||||
pos => {
|
||||
gpsCoords = { lat: pos.coords.latitude, lon: pos.coords.longitude };
|
||||
sessionStorage.setItem('gpsCoords', JSON.stringify(gpsCoords));
|
||||
el.innerHTML = '<span style="color:#388e3c">📍 Location captured</span>';
|
||||
},
|
||||
err => {
|
||||
|
|
@ -328,6 +332,7 @@
|
|||
async function startOver() {
|
||||
await fetch('/reset', { method: 'POST' });
|
||||
gpsCoords = null;
|
||||
sessionStorage.removeItem('gpsCoords');
|
||||
showStep(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue