[알게된 것] React Native iOS 현재위치 조회 대기시간 이슈

Chobby·2023년 11월 7일
1

알게된 것

목록 보기
29/50
post-thumbnail

😀문제상황

Geolocation.getCurrentPositioniOS 환경에서 실행하니 오랜 시간(평균 10초 이상)이 걸림
반면, Android는 문제없이 빠르게 위치를 반환했음


😁해결방법

if(Platform.OS === 'ios') {
	return new Promise((resolve, reject) => {
    	const id = Geolocation.watchPosition((pos) => {
    	Geolocation.clearWatch(id);
      	resolve(pos);
    }, (err) => {
    	if(err) {
        	reject(err);
    	}
	}, {enableHighAccuracy: true});
}

iOS는 따로 분기처리하여 getCurrentPosition을 사용하지 않고, watchPosition을 사용하니 훨씬 빠르고 비슷한 정확도의 위치가 반환되었음

profile
내 지식을 공유할 수 있는 대담함

0개의 댓글