파게로그

유용한 libs, APIs 본문

콤퓨타 왕기초/JS

유용한 libs, APIs

파게 2020. 10. 15. 16:25

위치 얻어오기(https://developer.mozilla.org/ko/docs/Web/API/Geolocation_API)

navigator.geolocation.getCurrentPosition()

 

날씨 API(https://openweathermap.org/)

 

async programming with Promise

Promise (https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise)

Using promises (https://wiki.developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Using_promises)

function getWeather(coordsObj) {
    const lati = coordsObj.latitude;
    const longi = coordsObj.longitude;

    fetch(
        `https://api.openweathermap.org/data/2.5/weather?lat=${lati}&lon=${longi}&appid=${API_KEY}&units=metric`
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        const temperature = json.main.temp;
        const place = json.name;
        weather_span.innerHTML = `${temperature} Celsius @ ${place}`;
    });
}

'콤퓨타 왕기초 > JS' 카테고리의 다른 글

33 Concepts Every JS Developer Should Know  (0) 2020.10.19
JSON 다루기  (0) 2020.10.15
DOM에서 element 생성 또는 제거  (0) 2020.10.15
array  (0) 2020.10.15
event, event handlers (2)  (0) 2020.10.12
Comments