Corrections et optimisations géolocalisation
This commit is contained in:
@ -5,6 +5,7 @@ import { PlayerLocation, setLastLocation } from './features/location/locationSli
|
||||
import store from './store'
|
||||
import { useEffect } from 'react'
|
||||
import { socket } from './socket'
|
||||
import { Constants } from '@/constants/Constants'
|
||||
|
||||
const LOCATION_TASK = "fetch-geolocation"
|
||||
|
||||
@ -16,7 +17,6 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
|
||||
const { locations } = data
|
||||
const lastLoc: Location.LocationObject = locations.at(-1)
|
||||
store.dispatch(setLastLocation(lastLoc))
|
||||
console.log("sending-loc", lastLoc, socket.active)
|
||||
const playerId = store.getState().game.playerId
|
||||
if (socket.active && playerId) {
|
||||
const lastLocToSend: PlayerLocation = {
|
||||
@ -25,11 +25,11 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
|
||||
latitude: lastLoc.coords.latitude,
|
||||
speed: lastLoc.coords.speed ?? 0,
|
||||
accuracy: lastLoc.coords.accuracy ?? 0,
|
||||
altitude: lastLoc.coords.accuracy ?? 0,
|
||||
altitude: lastLoc.coords.altitude ?? 0,
|
||||
altitudeAccuracy: lastLoc.coords.altitudeAccuracy ?? 0,
|
||||
timestamp: new Date(lastLoc.timestamp).toISOString(),
|
||||
}
|
||||
socket.emit('last-location', { playerId: playerId, loc: lastLocToSend })
|
||||
socket.emit('last-location', lastLocToSend)
|
||||
}
|
||||
})
|
||||
|
||||
@ -49,10 +49,10 @@ export async function startGeolocationService(): Promise<void | (() => void)> {
|
||||
|
||||
if (Platform.OS !== "web") {
|
||||
await Location.startLocationUpdatesAsync(LOCATION_TASK, {
|
||||
accuracy: Location.Accuracy.BestForNavigation,
|
||||
accuracy: Constants.LOCATION_ACCURACY,
|
||||
activityType: Location.ActivityType.OtherNavigation,
|
||||
deferredUpdatesInterval: 100,
|
||||
timeInterval: 100,
|
||||
deferredUpdatesInterval: 1000,
|
||||
timeInterval: 1000,
|
||||
foregroundService: {
|
||||
killServiceOnDestroy: false,
|
||||
notificationBody: "Géolocalisation activée pour « Traintrape-moi »",
|
||||
@ -63,7 +63,7 @@ export async function startGeolocationService(): Promise<void | (() => void)> {
|
||||
return async () => await Location.stopLocationUpdatesAsync(LOCATION_TASK)
|
||||
}
|
||||
else {
|
||||
const locationSubscription = await Location.watchPositionAsync({accuracy: Location.Accuracy.BestForNavigation}, location_nouveau => store.dispatch(setLastLocation(location_nouveau)))
|
||||
const locationSubscription = await Location.watchPositionAsync({ accuracy: Constants.LOCATION_ACCURACY }, location_nouveau => store.dispatch(setLastLocation(location_nouveau)))
|
||||
return locationSubscription.remove
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user