Dev study and notes

바닐라 JS로 크롬 앱 만들기 8장 강좌들 노마드코더 무료강좌 본문

Building & Learning/바닐라JS-노마드코더

바닐라 JS로 크롬 앱 만들기 8장 강좌들 노마드코더 무료강좌

devlunch4 2025. 1. 17. 16:20
반응형

바닐라 JS로 크롬 앱 만들기 8장 강좌들 노마드코더 무료강좌

노마드코더 바닐라JS 자바스크립트 강좌 #8.0 Geolocation 요약:
1. Geolocation API를 사용하면 사용자의 현재 위치 정보를 가져올 수 있습니다.
2. navigator.geolocation.getCurrentPosition 메서드를 통해 위도와 경도를 얻는 방법을 설명합니다.
3. 위치 정보는 콜백 함수로 처리되며, 성공 및 에러를 처리하는 구조를 배우게 됩니다.

index.html 과 weather.js 생성하면됩니다.

*weather.js 소스코드

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);



그리고 최종적으로 TODO와 명언, 날씨 서비스를 제공하는 웹 앱을 생성하게 됩니다.

끝!

반응형
Comments