💛 8.0 Geolocation
🔷 navigator.geolocation.getCurrentPosition()
- wifi, gps 등 정보
function onGeoOk(position) {
console.log(position);
const lat = position.coords.latitude;
const lng = position.coords.longitude;
console.log("You live in", lat, lng)
}
function onGeoError() {
alert("Can't find you. No weather for you.")
}
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError)
🔷 openweathermap (api 사이트)
https://openweathermap.org/api
💛 8.1 Weather API
<https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid=>{API key}
<https://api.openweathermap.org/data/2.5/weather?lat=35.1685178&lon=129.1124807&appid={API KEY}
🔷 error
링크 : https://openweathermap.org/faq#error401
🔷 키 문제인듯
https://api.openweathermap.org/data/2.5/weather?lat=35.1685178&lon=129.1124807&appid={API KEY}
- 확인 해보니 가입시 등록한 메일로 확인 인증을 안해서 허용이 안되고 있었음💦💦
🔷 출력 JSON 예시
🔷 fetch(url) :
- 패치는 promise임
- 화씨 → 섭씨
- 끝에 units=metric 추가
- https://api.openweathermap.org/data/2.5/weather?lat=35.1758497&lon=129.1023127&appid={API KEY}&units=metric
본 포스팅은 nomadcoder '바닐라 JS로 크롬 앱 만들기' 강의를 들으며 작성한 글 입니다.
'WEB 공부 > JavaScript' 카테고리의 다른 글
[Memo] #7 To Do List | 바닐라 JS로 크롬 앱 만들기 (0) | 2023.02.05 |
---|---|
[Memo] #6 Quotes and Background (0) | 2023.02.05 |
[Memo] #5 Clock | 바닐라 JS로 크롬 앱 만들기 (0) | 2023.02.05 |
[Memo] #4 LOGIN | 바닐라 JS로 크롬 앱 만들기 (0) | 2023.02.05 |
[Memo] #3 Javascript on the Browser | 바닐라 JS로 크롬 앱 만들기 (0) | 2023.02.05 |