From 59493ac784ece591f71b32e536191c994b4c43ad Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Fri, 24 Jul 2026 21:17:20 +0700 Subject: [PATCH] Geolocation: coarse fallback + clearer native error copy (v1.0.75) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The native Geolocation fix only takes effect once the APK is rebuilt — the current phone build still uses navigator.geolocation, hence the error. To make the rebuilt version more robust: - If a high-accuracy fix fails/times out (common indoors or weak GPS), retry with a coarse (network/wifi) fix and a longer window before giving up. This rescues most "Location unavailable" cases. - On native, the "unavailable" toast now tells the user to turn on Location/GPS AND allow the app permission, instead of the generic web message. Co-authored-by: shakespeare.diy --- package.json | 2 +- src/lib/geolocation.ts | 29 ++++++++++++++++++++++------- src/pages/MapPage.tsx | 4 +++- 3 files changed, 26 insertions(+), 9 deletions(-) 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', }); }