Solve Problem/React Native
[React Native] 현재 위치 위도/경도 알기
안다희
2020. 4. 29. 01:50
728x90
- 환경
react-native: 0.61.5
@react-native-community/geolocation: 2.0.2
- 라이브러리
https://github.com/react-native-community/react-native-geolocation
react-native-community/react-native-geolocation
Geolocation APIs for React Native. Contribute to react-native-community/react-native-geolocation development by creating an account on GitHub.
github.com
- 설치
yarn add @react-native-community/geolocation
- 설정
AndroidManifest.xml 에 추가
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Info.plist 에 추가
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string></string>
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
첫 번째 키는 원래 있음
- Usage
Geolocation.getCurrentPosition(async ({coords}) => {
const lat = coords.latitude;
const lon = coords.longitude;
// use lat, lon
});