๐Ÿ“”
web_study
  • JavaScript
  • ์—˜๋ฆฌ_์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธ
      • ํด๋ž˜์Šค ์˜ˆ์ œ์™€ ์ฝœ๋ฐฑํ•จ์ˆ˜
      • ์—ฐ์‚ฐ์ž boolean
      • ํ•จ์ˆ˜ ์ •์˜, ํ˜ธ์ถœ ๊ทธ๋ฆฌ๊ณ  ์ฝœ๋ฐฑ
      • ๋ณ€์ˆ˜ํƒ€์ž…๊ณผ object ์ฐจ์ด์ 
    • JavaScript async ์™€ await
    • JavaScript Promise
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ callback
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ json
    • ์œ ์šฉํ•œ 10๊ฐ€์ง€ ๋ฐฐ์—ด ํ•จ์ˆ˜๋“ค
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐฐ์—ด(array)
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ object
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ (class vs object) ๊ฐ์ฒด์ง€ํ–ฅ ์–ธ์–ด
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ•จ์ˆ˜
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์—ฐ์‚ฐ.๋ฐ˜๋ณต๋ฌธ
    • ๋ฐ์ดํ„ฐํƒ€์ž…, data types, let vs var, hoisting
    • script async ์™€ defer์˜ ์ฐจ์ด์  ์ฝ˜์†” ์ถœ๋ ฅ
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—ญ์‚ฌ
  • ์ƒํ™œ์ฝ”๋”ฉ
    • ์žฌ๊ท€ํ•จ์ˆ˜
    • ์ •๊ทœ ํ‘œํ˜„์‹
    • ๊ฐ์ฒด์ง€ํ–ฅ
      • ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
      • ์ƒ์„ฑ์ž์™€ new
      • ์ „์—ญ๊ฐ์ฒด
      • this
      • ์ƒ์†
      • prototype
      • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
      • object
      • ๋ฐ์ดํ„ฐ ํƒ€์ž…
      • ์ฐธ์กฐ
    • ํ•จ์ˆ˜์ง€ํ–ฅ
      • ์œ ํšจ๋ฒ”์œ„
      • ๊ฐ’์œผ๋กœ์„œ์˜ ํ•จ์ˆ˜์™€ ์ฝœ๋ฐฑ
      • ํด๋กœ์ €
      • arguments
      • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • UI API, ๋ฌธ์„œ
    • ๋ชจ๋“ˆ
    • ๊ฐ์ฒด
    • ๋ฐฐ์—ด
    • ํ•จ์ˆ˜
    • ๋ฐ˜๋ณต๋ฌธ
    • ์กฐ๊ฑด๋ฌธ
    • ์ˆซ์ž์™€๋ฌธ์ž
    • ๋ณ€์ˆ˜
    • ๋น„๊ต
  • ๋…ธ๋งˆ๋“œ ์ฝ”๋”
    • Getting the Weather part One Geolocation
    • Image Background
    • TO DO List
    • Saving the User Name
    • Clock part One
    • ์กฐ๊ฑด๋ฌธ ( if , else, and, or)
    • evnet handlers
    • Function
    • Objects
    • Arrays
    • Variable(๋ณ€์ˆ˜!)
    • Javascript
  • javascript30
    • Dram Kit
    • clock
    • Css Javascript
    • Array Cardio
    • flex panels
    • type ahead
    • Canvas Draw
    • Speech Synthesis
    • Whack A Mole
  • web standard
    • script ๋ถ€๋ถ„
    • form๋ถ€๋ถ„
    • ์›น์ ‘๊ทผ์„ฑ
    • <meta>
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ_์ด๋ก 
    • ๊ธฐ๋ณธ์ง€์‹(JAVASCRIPT)
    • ๊ธฐ๋ณธ์ง€์‹(CSS)
    • ๊ธฐ๋ณธ์ง€์‹(HTML)
    • ๊ธฐ๋ณธ์ง€์‹(HTTP)
    • Dom
    • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ํ”„๋ ˆ์ž„์›Œํฌ, ํ”Œ๋กœ๊ทธ์ธ
Powered by GitBook
On this page
  • Getting the Weather part One Geolocation
  • API

Was this helpful?

  1. ๋…ธ๋งˆ๋“œ ์ฝ”๋”

Getting the Weather part One Geolocation

Getting the Weather part One Geolocation

const API_KEY = "ํ‚ค๊ฐ’ ๋„ฃ์œผ์ฃผ๋ฉด๋จ ";
const WEATHER_API = "https://api.openweathermap.org/data/2.5/weather?";

const weather = document.querySelector(".js-weather .weather__text");

function getWeather(coords) {
  fetch(
    `${WEATHER_API}lat=${coords.lat}&lon=${
      coords.lng
    }&appid=${API_KEY}&units=metric`
  )
    .then(response => response.json())
    .then(json => { // then์„ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” fetch๊ฐ€ ์™„๋ฃŒ๋˜๊ธธ ๊ธฐ๋‹ค๋ ค์•ผํ•˜๊ธฐ๋•Œ๋ฌธ์ด๋‹ค. 
      const name = json.name;
      const temperature = json.main.temp;
      weather.innerHTML = `${Math.floor(temperature)}ยฐ @ ${name}`;
    });
}

function handleGeoSuccess(position) {
  const lat = position.coords.latitude;
  const lng = position.coords.longitude;
  const coords = {
    lat, // key ์™€ value๊ฐ’์ด ๊ฐ™์œผ๋ฉด ์ƒ๋žต ๊ฐ€๋Šฅํ•˜๋‹ค.
    lng
  };
  localStorage.setItem("coords", JSON.stringify(coords));
  getWeather(coords);
}

function handleGeoFailure() {
  console.log("no location");
}

function loadWeather() {
  const currentCoords = localStorage.getItem("coords");
  if (currentCoords !== null) {
    const parsedCoords = JSON.parse(currentCoords);
    getWeather(parsedCoords);
    return;
  } else {
    navigator.geolocation.getCurrentPosition(
      handleGeoSuccess,
      handleGeoFailure
    );
  }
}

function init() {
  loadWeather();
}

init();

API

API๋Š” ํŠน์ • ์›น์‚ฌ์ดํŠธ๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์–ป๊ฑฐ๋‚˜ ์ปดํ“จํ„ฐ๋ผ๋ฆฌ ์†Œํ†ตํ•˜๊ธฐ ์œ„ํ•ด ๊ณ ์•ˆ๋œ๊ฒƒ์ด๋‹ค.

Previous๋น„๊ตNextImage Background

Last updated 3 years ago

Was this helpful?