이 글의 성격은 무엇인가요?
질문 / 문제 해결
내용을 설명해주세요
getCurrentLocation을 사용 중, 배포된 앱을 지하철에서 테스트 했을 때 확인된 상황입니다.
해당 메소드 사용 부분 근처에서 원래 로드 시간보다 10초가 더 걸리는 상황입니다.
위치 정보를 정상적으로 가져 오지 못 하는 상황에서 **getCurrentLocation의 반환이 어떻게 되는지 궁금합니다!
getCurrentGeoLocation: async (timeout = 2000) => {
try {
const locationPromise = getCurrentLocation({
accuracy: Accuracy.Balanced,
});
const timeoutPromise = new Promise<null>(resolve =>
setTimeout(() => resolve(null), timeout)
);
const location = await Promise.race([locationPromise, timeoutPromise]);
if (location && location.coords) {
const geoLocation = {
lat: location.coords.latitude,
lng: location.coords.longitude,
};
// 성공 시 로컬 스토리지에 저장
LastKnownLocationStorage.set(geoLocation);
return geoLocation;
}
// 위치 획득 실패 또는 타임아웃
throw new Error('Location not available');
} catch (error) {
// 1차 fallback: 저장된 마지막 위치
const lastKnownLocation = await LastKnownLocationStorage.get();
if (lastKnownLocation) {
return {
lat: lastKnownLocation.lat,
lng: lastKnownLocation.lng,
};
}
// 2차 fallback: 강남역 좌표
return GANGNAM_STATION_LOCATION;
}
},
위 코드와 같이 사용중입니다.