반응형
#8.0 Geolocation
아래의 코드를 입력하면 내가 있는 곳의 위도와 경도를 콘솔에 띄울 수 이따따ㅏ따. 루꼣디스뷰리.
function onGeoOk(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);
#8.1 Weather API
https://openweathermap.org/api 요기에서 API 가져올 수 있다.
API는 다른 서버와 이야기할 수 있는 방법이다.
units도 조정할 수 있다. url 뒤에 &units=metric를 추가하면 된다.
fetch는 promise다.
흠 로컬에서는 잘 된다.
반응형
'Study > Web' 카테고리의 다른 글
[유튜브 클론 코딩] #5.0~5.9 Templates(템플릿) (0) | 2021.09.12 |
---|---|
[유튜브 클론 코딩] #3.9~4.8 Routers(라우터) (0) | 2021.09.12 |
[JS] 바닐라 JS | #7.0~7.8) To-Do List 만들기 (2) | 2021.08.08 |
[JS] 바닐라 JS | #5.0~5.3) 시계 만들기 (0) | 2021.08.04 |
[JS] 바닐라 JS | #4.0~4.6) 입력폼 만들기 (0) | 2021.08.03 |