반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 서울
- 시놀로지나스
- 가상환경
- 캠핑
- MSSQL
- SQL
- Excel
- 시놀로지
- synology
- apk
- 엑셀
- 연곡해변
- 장고
- 맛집
- 수도권 근교
- Django
- docker
- react native
- 강릉
- ReactNaitve
- Firebase
- 리엑트
- react
- Expo
- reactnative
- 캠핑장
- 리액트
- 나스
- 함수
- Nas
Archives
- Today
- Total
차근차근 생활 & 코딩
[React Native] RN - 카카오 로컬 API 사용하기(좌표를 주소로) 본문
반응형
안녕하세요.
이번 시간에는 카카오 로컬 API를 활용하여 좌표를 주소로 변경하는 작업을 해보도록 하겠습니다.
Installing
npm 또는 yarn을 통하여 axios를 설치하여 줍니다.
npm install axios --save
또는
yarn add axios
axios 데이터 불러오기
카카오 개발자 사이트에 접속
① 내 어플리케이션 > 앱 설정 > 앱키로 접속해 줍니다.
② REST API 키를 복사합니다.
③ 복사한 REST API 키를 React Native 코드에 넣어 줍니다.
결과 확인하기
전체 코드
import React, {useState} from 'react';
import {Text, View, Button} from 'react-native';
import axios from 'axios';
export default function App() {
const [locationObj, setLocationObj] = useState({});
const x = '126.9539484';
const y = '37.3097165';
const _callApi = async () => {
try {
let res = await axios
.get(
`https://dapi.kakao.com/v2/local/geo/coord2address.json?input_coord=WGS84&x=${x}&y=${y}`,
{
headers: {
Authorization: 'KakaoAK 1234567891234567891234567891234', // REST API 키
},
},
)
.then(res => {
const location = res.data.documents[0];
setLocationObj({
si: location.address.region_1depth_name,
gu: location.address.region_2depth_name,
dong: location.address.region_3depth_name,
// locationX: location.address.x,
// locationY: location.address.y,
});
});
console.log(locationObj);
} catch (error) {
console.log(error.message);
}
};
return (
<View>
<Button title="Api 불러오기 버튼" onPress={_callApi} />
<Text>{locationObj.si}</Text>
<Text>{locationObj.gu}</Text>
<Text>{locationObj.dong}</Text>
</View>
);
}
수고하셨습니다.
[React Native] RN - 현재 위치 좌표 불러오기
안녕하세요. 이번시간에는 현재 위치에서 좌표를 불러오는 방법에 대해서 알려드리도록 하겠습니다. Installing npm install @react-native-community/geolocation --save 안드로이드 권한설정 위치정보 권한 설정
ssilook.tistory.com
반응형
'IT > REACT NATIVE(리액트 네이티브)' 카테고리의 다른 글
[React Naitve] ScrollView 스크롤 숨기기 (2) | 2021.12.27 |
---|---|
[React Native] RN - 현재 위치 좌표 불러오기 (2) | 2021.12.20 |
[ReactNative] RN - firebase storage 이미지 가져오기 (0) | 2021.12.15 |
[React Native] RN - Android Splash 이미지 적용하기 (2) | 2021.12.06 |
[React Native] RN - APK 추출하기 1편(Android Studio로 APK 추출하기) (2) | 2021.12.06 |
Comments