Commit 7767d177 authored by yannickjacqueline's avatar yannickjacqueline Committed by Benjamin Guedj
Browse files

fix(carto): correction sur la récupération de la localisation (#675)

parent 755adced
......@@ -53,3 +53,8 @@ export enum CartoFilterEnum {
}
export const MAPVIEW_MIN_ZOOM_LEVEL = 10;
export const ERROR_LOCATION_PROVIDER_UNAVAILABLE_MESSAGE =
"Location provider is unavailable. Make sure that location services are enabled.";
export const GET_POSITION_MAX_ATTEMPTS = 60;
......@@ -66,8 +66,34 @@ const SearchByPostalCode: React.FC<Props> = ({
setLocationPermissionIsGranted(true);
setIsLoading(true);
try {
const currentLocation = await Location.getCurrentPositionAsync({});
updateUserLocation(currentLocation.coords);
let currentLocation = undefined;
let locationSuccess = false;
let getPositionAttempts = 0;
// Il y a un temps de latence entre le moment où on autorise la géolocalisation
// et le moment où le getCurrentPositionAsync() retourne une localication
// donc tant qu'il ne retourne rien, on le rappelle
while (!locationSuccess) {
try {
currentLocation = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Lowest,
});
locationSuccess = true;
// eslint-disable-next-line no-empty
} catch (ex: unknown) {
getPositionAttempts = getPositionAttempts + 1;
if (
// Si l'exception remontée n'est pas une erreur de service non-disponible
// Ou si le nombre de tentatives a été dépassé, on arrête les rappels
!JSON.stringify(ex).includes(
AroundMeConstants.ERROR_LOCATION_PROVIDER_UNAVAILABLE_MESSAGE
) ||
getPositionAttempts > AroundMeConstants.GET_POSITION_MAX_ATTEMPTS
) {
locationSuccess = true;
}
}
}
updateUserLocation(currentLocation ? currentLocation.coords : undefined);
} catch {
updateUserLocation(undefined);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment