diff --git a/package.json b/package.json index 2800d58..5a93613 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "skate-spots", "private": true, - "version": "1.0.74", + "version": "1.0.75", "type": "module", "homepage": "https://skate-spots.com", "scripts": { diff --git a/src/lib/geolocation.ts b/src/lib/geolocation.ts index 3c6ff22..0e941b4 100644 --- a/src/lib/geolocation.ts +++ b/src/lib/geolocation.ts @@ -99,12 +99,27 @@ export async function getCurrentPosition(): Promise { throw new GeolocationError('denied', 'Location permission denied.'); } - const pos = await native.getCurrentPosition({ - enableHighAccuracy: true, - timeout: 10000, - maximumAge: 30000, - }); - return { lat: pos.coords.latitude, lng: pos.coords.longitude }; + // First try a precise fix. High accuracy can fail/time out indoors or + // with a weak GPS signal, which shows up as "unavailable" or "timeout". + try { + const pos = await native.getCurrentPosition({ + enableHighAccuracy: true, + timeout: 10000, + maximumAge: 30000, + }); + return { lat: pos.coords.latitude, lng: pos.coords.longitude }; + } catch (highAccErr) { + // Fall back to a coarse (network/cell/wifi) fix with a longer window. + // This rescues the common "GPS can't lock" case that otherwise looks + // like a hard failure. + console.warn('[geolocation] high-accuracy failed, trying coarse:', highAccErr); + const pos = await native.getCurrentPosition({ + enableHighAccuracy: false, + timeout: 20000, + maximumAge: 120000, + }); + return { lat: pos.coords.latitude, lng: pos.coords.longitude }; + } } catch (err) { if (err instanceof GeolocationError) throw err; const msg = (err instanceof Error ? err.message : String(err)).toLowerCase(); @@ -114,7 +129,7 @@ export async function getCurrentPosition(): Promise { if (msg.includes('timeout') || msg.includes('timed out')) { throw new GeolocationError('timeout', 'Location request timed out.'); } - // "location disabled", "unavailable", etc. + // "location disabled", "unavailable", plugin-not-implemented, etc. throw new GeolocationError('unavailable', err instanceof Error ? err.message : 'Location unavailable.'); } } diff --git a/src/pages/MapPage.tsx b/src/pages/MapPage.tsx index 50d5ea7..9c35647 100644 --- a/src/pages/MapPage.tsx +++ b/src/pages/MapPage.tsx @@ -665,7 +665,9 @@ export default function MapPage() { setNearMeError('unavailable'); toast({ title: 'Location unavailable', - description: 'Your location could not be determined. Make sure location services are enabled.', + description: isNativeGeolocation() + ? 'Turn on Location/GPS in your phone settings, allow location for SkateSpots (Settings → Apps → SkateSpots → Permissions), then try again.' + : 'Your location could not be determined. Make sure location services are enabled.', variant: 'destructive', }); }