IT하는 참새
React-Native 빠르게 시작하기 (4) 본문
리액트 네이티브에서 GPS기능 사용하기
사용 방법은 크게 2가지로 나뉜다
1) 공식 React-Native API 이용
2) Expo API 이용 (권장)
https://docs.expo.io/versions/latest/sdk/location/
Location - Expo Documentation
heading (number) -- Horizontal direction of travel of this device, measured in degrees starting at due north and continuing clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on.
docs.expo.io

App.js 수정
- GPS 기능을 이용하기 위한 클래스 임포트
- App function을 클래스 형태로 변경

추가 설명

React.Component를 이용하여 클래스를 구성했다면 특정 생명주기를 따르게 된다
이 때, componentDidMount 메소드를 이용하여 GPS등록을 수행한다 (안드로이드의 액티비티 생명주기와 유사)

현재 위치를 가져오는 메소드는 getCurrentPositionAsync(options)이다
공식문서에서 비동기 처리하도록 안내하고 있으므로 async, await을 이용하여 처리한다

앱의 하드웨어기능을 포함한 특정 기능을 사용할 때에는 권한을 요청해야 한다
GPS도 마찬가지 이므로, GPS권한 사용을 요청하는 코드가 포함되어야 정상적으로 동작한다

작성한 getLocation객체를 수정한다

실행 결과 expo-client에서는 Unrecognized event로 표시된다

콘솔창에서는 Object로 정확히 표시된다

위치객체는 다음과 같이 파싱할 수 있다

또는 JSX문법을 사용하여 파싱할 수 있다

expo cli에서 Unrecognized event오류를 해결하는 방법
https://stackoverflow.com/questions/62655056/unrecognized-event-react-native-redux
Unrecognized event React Native Redux
I am new on redux. I am using redux with react-native. I just created a simple app that has RGB colour stored on redux and I am using and updating state with a component. The output is fine but I am
stackoverflow.com
'프로그래밍 > ReactNative' 카테고리의 다른 글
React-Native 빠르게 시작하기 (5) (0) | 2020.07.14 |
---|---|
React-Native 빠르게 시작하기 (3) (0) | 2020.07.12 |
React-Native 빠르게 시작하기 (2) (0) | 2020.07.12 |
React-Native 빠르게 시작하기 (1) (0) | 2020.07.11 |