11import * as Location from 'expo-location' ;
22import * as TaskManager from 'expo-task-manager' ;
3- import { AppState , type AppStateStatus , Platform } from 'react-native' ;
3+ import { AppState , type AppStateStatus } from 'react-native' ;
44
55import { setUnitLocation } from '@/api/units/unitLocation' ;
66import { registerLocationServiceUpdater } from '@/lib/hooks/use-background-geolocation' ;
77import { logger } from '@/lib/logging' ;
8+ import { isWeb } from '@/lib/platform' ;
89import { loadBackgroundGeolocationState } from '@/lib/storage/background-geolocation' ;
910import { SaveUnitLocationInput } from '@/models/v4/unitLocation/saveUnitLocationInput' ;
1011import { useCoreStore } from '@/stores/app/core-store' ;
1112import { useLocationStore } from '@/stores/app/location-store' ;
1213
13- const isWeb = Platform . OS === 'web' ;
1414const LOCATION_TASK_NAME = 'location-updates' ;
1515
1616// Helper function to send location to API
@@ -155,7 +155,12 @@ class LocationService {
155155 async startLocationUpdates ( ) : Promise < void > {
156156 // On web, use a lightweight browser geolocation watcher instead of expo-location/TaskManager
157157 if ( isWeb ) {
158- if ( ! this . locationSubscription && 'geolocation' in navigator ) {
158+ if ( ! ( 'geolocation' in navigator ) ) {
159+ logger . warn ( { message : 'Geolocation API not available in this browser' } ) ;
160+ return ;
161+ }
162+
163+ if ( ! this . locationSubscription ) {
159164 const watchId = navigator . geolocation . watchPosition (
160165 ( pos ) => {
161166 const loc : Location . LocationObject = {
@@ -180,6 +185,7 @@ class LocationService {
180185 ) ;
181186 // Store a compatible subscription object
182187 this . locationSubscription = { remove : ( ) => navigator . geolocation . clearWatch ( watchId ) } as unknown as Location . LocationSubscription ;
188+ logger . info ( { message : 'Foreground location updates started' } ) ;
183189 }
184190 return ;
185191 }
0 commit comments