From ec6a6facd1f5705507d4ed66316ff77f797d2bee Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Wed, 3 Jun 2026 10:06:24 +0200 Subject: [PATCH] fix: centre map on user location at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Request foreground location permission on RecordingScreen mount so the map can find the user immediately. Camera now always has trackUserLocation set — 'default' when idle/paused (follows position, no rotation) and 'course' when recording (follows direction of travel). --- src/screens/RecordingScreen.tsx | 8 ++++++-- src/services/gps.ts | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/screens/RecordingScreen.tsx b/src/screens/RecordingScreen.tsx index 7b2bb1b..164aa47 100644 --- a/src/screens/RecordingScreen.tsx +++ b/src/screens/RecordingScreen.tsx @@ -6,7 +6,7 @@ import { activateKeepAwakeAsync, deactivateKeepAwake } from 'expo-keep-awake'; import { Map, Camera, GeoJSONSource, Layer, UserLocation } from '@maplibre/maplibre-react-native'; import type { LineLayerStyle } from '@maplibre/maplibre-react-native'; import { useRecordingStore } from '../store/recording'; -import { startGpsRecording, stopGpsRecording, requestLocationPermissions } from '../services/gps'; +import { startGpsRecording, stopGpsRecording, requestLocationPermissions, requestForegroundLocation } from '../services/gps'; import { RootStackParamList } from '../types'; import { colors } from '../theme'; import { useTheme } from '../ThemeContext'; @@ -27,6 +27,10 @@ export function RecordingScreen() { return () => { if (intervalRef.current) clearInterval(intervalRef.current); }; }, []); + useEffect(() => { + requestForegroundLocation(); + }, []); + useEffect(() => { if (keepAwake && status === 'recording') activateKeepAwakeAsync(); else deactivateKeepAwake(); @@ -94,7 +98,7 @@ export function RecordingScreen() { diff --git a/src/services/gps.ts b/src/services/gps.ts index 71d0c0a..8a23997 100644 --- a/src/services/gps.ts +++ b/src/services/gps.ts @@ -55,6 +55,11 @@ async function maybeNotifyKm(distanceMeters: number): Promise { }); } +export async function requestForegroundLocation(): Promise { + const { status } = await Location.requestForegroundPermissionsAsync(); + return status === 'granted'; +} + export async function requestLocationPermissions(): Promise { const { status: fg } = await Location.requestForegroundPermissionsAsync(); if (fg !== 'granted') return false;