diff --git a/src/lib/geolocation.ts b/src/lib/geolocation.ts index fd7382c..9ec71d2 100644 --- a/src/lib/geolocation.ts +++ b/src/lib/geolocation.ts @@ -228,7 +228,7 @@ async function getNativePosition(native: CapGeolocationPlugin): Promise - native.getCurrentPosition({ enableHighAccuracy: false, timeout: 15000, maximumAge: 60000 }), + native.getCurrentPosition({ enableHighAccuracy: false, timeout: 8000, maximumAge: 60000 }), ); const lat = pos?.coords?.latitude; const lng = pos?.coords?.longitude; @@ -340,7 +340,7 @@ function getWebPosition(): Promise { settled = true; cleanup(); reject(new GeolocationError('timeout', 'Location request timed out.')); - }, 25000); + }, 15000); // 1) watchPosition — first update wins (fast network fix). try { diff --git a/src/pages/MapPage.tsx b/src/pages/MapPage.tsx index 81c3877..45c9078 100644 --- a/src/pages/MapPage.tsx +++ b/src/pages/MapPage.tsx @@ -804,13 +804,29 @@ export default function MapPage() { useEffect(() => { if (isNativeGeolocation()) return; let cancelled = false; - getCurrentPosition() - .then(({ lat, lng }) => { - if (!cancelled) setUserLocation({ lat, lon: lng }); - }) - .catch(() => { - // Silent — user hasn't asked to be located yet. - }); + + const warm = () => + getCurrentPosition() + .then(({ lat, lng }) => { + if (!cancelled) setUserLocation({ lat, lon: lng }); + }) + .catch(() => { + // Silent — user hasn't asked to be located yet. + }); + + // Only warm up when permission is ALREADY granted — otherwise this fires the + // browser's "Allow location?" prompt the moment someone opens /map. + if (typeof navigator !== 'undefined' && navigator.permissions?.query) { + navigator.permissions + .query({ name: 'geolocation' as PermissionName }) + .then((status) => { + if (!cancelled && status.state === 'granted') warm(); + }) + .catch(() => { + /* permissions API unavailable — don't prompt */ + }); + } + return () => { cancelled = true; }; @@ -1432,6 +1448,29 @@ export default function MapPage() { compact /> + {/* Near Me — desktop parity (mobile has the floating control) */} + + {/* Clear filters */} {hasActiveFilters && (