navigator.geolocation.getCurrentPosition()
Geolocation.getCurrentPosition() 메서드는 장치의 현재 위치를 가져옵니다.
출처: mozilla
문법
navigator.geolocation.getCurrentPosition(success, error, [options]);
function onGeoOk() {}
function onGeoError() {}
function onGeoOk() {}
  function onGeoError() {
    alert("Can't find you. No weather for you.");
  }
function onGeoOk(position) {
    console.log(position);
  }
  function onGeoError() {
    alert("Can't find you. No weather for you.");
  }
콘솔:

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);
API란? 기본적으로 API는 다른 서버와 이야기할 수 있는 방법이다.
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&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].main} / ${data.main.temp}`;
        }));
이와같이 서버에서 받아온 날씨 정보들이 객체로 전달되어
이 값을 사용할 수 있는것 같다
function onGeoOk(position) {
    const lat = position.coords.latitude;
    const lng = position.coords.longitude;
    const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=${API_KEY}&units=metric`;
    console.log(url);
    fetch(url)
        .then(response => response.json()
        .then(data => {
                console.log(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].main} / ${data.main.temp}`;
        }));
  }
  function onGeoError() { 
    alert("Can't find you. No weather for you.");
  }
  
  navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);
완성된 코드 (API 키는 넣어놓지 않았다)