오픈웨더앱에서 날씨 api 를 받아오기로
Сurrent weather and forecast - OpenWeatherMap
Access current weather data for any location on Earth including over 200,000 cities! The data is frequently updated based on the global and local weather models, satellites, radars and a vast network of weather stations. how to obtain APIs (subscriptions w
openweathermap.org
- 회원가입
- 자동으로 내 api 주소 만들어짐 (MyAPI가서 확인ㄱㄱ)
- 원하는 api 골라서 (나는 Current Weather Data로 골라봄)
- 내가 필요한 지역에 맞게 코드 수정해주고 내API키 넣기
- fetch로 받아오기
https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API key}
*위치경도로 지역 넣어줄 수도 있고 이름으로 넣어줄 수도 있는데, 나는 위치경도를 구글링해서 적용해봤지만 안되길래 이름으로 검색해서 넣어줌!
나는 여기서 지역, 온도, 날씨 이렇게 3가지만 가져오고 싶음
완성코드 타란!
fetch("https://api.openweathermap.org/data/2.5/weather?q=Seoul,kr&appid={본인키넘버}")
.then((response) => response.json())
.then((data) => {
$('#names-q1').empty();
let main = data['weather'][0]['main'];
let temp = data['main']['temp'];
let location = data['name'];
let temp_html = `
<li>${location}</li>
<li>${temp}</li>
<li>${main}</li>
`;
$('#names-q1').append(temp_html);
})
'What I Learnd' 카테고리의 다른 글
git/gitHub 으로 협업하기 step by step (0) | 2023.05.18 |
---|---|
SwiperJS 슬라이드 라이브러리 사용해보기 (0) | 2023.05.17 |
git & github으로 협업하기 (git 기초) (0) | 2023.05.16 |
웹 스크래핑(크롤링) 기초 [Beautiful Soup 뷰티불수프 라이브러리] (0) | 2023.05.04 |
mongoDB 사용하는 법 & pymongo 요약 (0) | 2023.05.04 |