Geolocation: coarse fallback + clearer native error copy (v1.0.75)

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 <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-07-24 21:17:20 +07:00
parent 04b8b0a8b1
commit 59493ac784
3 changed files with 26 additions and 9 deletions

View file

@ -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": {

View file

@ -99,12 +99,27 @@ export async function getCurrentPosition(): Promise<GeoCoords> {
throw new GeolocationError('denied', 'Location permission denied.');
}
// 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<GeoCoords> {
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.');
}
}

View file

@ -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',
});
}