diff --git a/frontend/src/pages/Properties/PropertyDetail.js b/frontend/src/pages/Properties/PropertyDetail.js index 5387612..cfaa121 100644 --- a/frontend/src/pages/Properties/PropertyDetail.js +++ b/frontend/src/pages/Properties/PropertyDetail.js @@ -353,6 +353,9 @@ const PropertyDetail = () => { const [gpsSamples, setGpsSamples] = useState([]); // recent raw samples for smoothing const [gpsDistance, setGpsDistance] = useState(0); const [gpsAccuracy, setGpsAccuracy] = useState(null); + const [gpsFixAgeMs, setGpsFixAgeMs] = useState(null); + const [gpsReady, setGpsReady] = useState(false); + const [warmWatchId, setWarmWatchId] = useState(null); const [isSnapPreview, setIsSnapPreview] = useState(false); const [showAddMenu, setShowAddMenu] = useState(false); // Modal picker to ensure options show reliably on mobile @@ -378,6 +381,28 @@ const PropertyDetail = () => { fetchPropertyDetails(); }, [id]); // eslint-disable-line react-hooks/exhaustive-deps + // Start a passive GPS watch when the page mounts to warm up the fix + useEffect(() => { + if (!navigator.geolocation) return; + if (warmWatchId) return; // already running + const id = navigator.geolocation.watchPosition( + (pos) => { + const { latitude, longitude, accuracy } = pos.coords; + addSampleAndSmooth(latitude, longitude, accuracy); + }, + (err) => { + console.warn('Warm GPS watch error', err?.message); + }, + { enableHighAccuracy: true, maximumAge: 1000, timeout: 20000 } + ); + setWarmWatchId(id); + return () => { + try { if (id) navigator.geolocation.clearWatch(id); } catch {} + setWarmWatchId(null); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + // Load recent history when property is available useEffect(() => { if (!property?.id) return; @@ -997,7 +1022,10 @@ const PropertyDetail = () => { GPS Points Mode Points: {gpsTracePoints.length} Distance: {(gpsDistance * 3.28084).toFixed(0)} ft - {gpsAccuracy != null && Accuracy: ±{Math.round(gpsAccuracy)} m} + + + Fix {gpsReady ? 'Good' : 'Improving'}{gpsAccuracy != null ? ` • ±${Math.round(gpsAccuracy)} m` : ''} +