👩🦰 사용자의 위치 얻기
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);


완성 코드
const API_KEY = "482309f68467f0f5584302302ae944bf"
function onGeoOk(position){
const lat = position.coords.latitude;
const lon = position.coords.longitude;
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}&units=metric`
fetch(url)
.then((response) => response.json())
.then((data) =>{
const weather = document.querySelector('#weather span:first-child');
const city = document.querySelector('#weather span:last-child');
city.innerText = data.name;
weather.innerText = `${data.weather[0].description} /${data.main.temp} `;
})
}
function onGeoError(){
alert("Can't find you. No weather for you")
}
navigator.geolocation.getCurrentPosition(onGeoOk,onGeoError);