๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๋ฐ”๋‹๋ผ JS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ :#8.0-8.2

change upยท2023๋…„ 6์›” 20์ผ
1

Weather ๊ธฐ๋Šฅ๊ตฌํ˜„

const API_KEY ='15';

function onGeoOk(position) {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
console.log("You alive in" ,lat ,lon)
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:nth-child(2)")
const city = document.querySelector("#weather span:nth-child(1)")
const imogi = document.querySelector("#weather span:nth-child(3)")
imogi.innerHTML = whetherNow(data.weather[0].main);
weather.innerText = ${data.weather[0].main};
city.innerText = data.name;
} );
}
function whetherNow(weatherType) {
if (weatherType === "Rain") {
return '๐ŸŒง๏ธ';
}
}
function onGeoError() {
alert( "you are in out side of earth");
}
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);

//getCurrentPosition(positioncallback,errorcallback)


๋“œ๋””์–ด...! ๋…ธ๋งˆ๋“œ ๊ฐ•์˜๊ฐ€ ๋๋‚˜์„œ css๋„ ๋ฐค์ƒˆ๋„๋ก ๊พธ๋ช„๋Š”๋ฐ.. ๊นƒํ—™์— ์˜ฌ๋ ค ๋ฐฐํฌ๋งŒ ๋‚จ์•˜๋Š”๋ฐ
ํ‘ธ์‰ฌํ•˜๋‹ค๊ฐ€ ๋ธŒ๋žœ์น˜๊ฐ€ ๊ผฌ์—ฌ๋ฒ„๋ ค์„œ.... ๋งํ–ˆ๋‹ค... ๊นƒ ์ด๊ทธ๋…ธ์–ด๋„ ์ด๊ทธ๋…ธ์–ด ํ•˜๋ผ๋Š” ํŒŒ์ผ์€ ์•ˆํ•˜๊ณ  ๋‹ค๋ฅธํŒŒ์ผ๋งŒ
์ด๊ทธ๋…ธ์–ด ํ•ด๋ฒ„๋ ค์„œ ๋‚ผ ๋ฐฐํฌ์— ๋‹ค์‹œ๋„์ „ ํ•ด์•ผ๊ฒ ๋‹ค.
์—˜๋ฆฌ์Šค sw5๊ธฐ ์Šคํ„ฐ๋””๋กœ ๋งŒ๋“  ํ”„๋กœ์ ํŠธ๋ผ ์—˜๋ฆฌ์Šค ํฐํŠธ๋ฅผ ๋„ฃ๊ณ  , ๋ฐฐ๊ฒฝํ™”๋ฉด ์‚ฌ์ง„๋„ ์—˜๋ฆฌ์Šค ์บ๋ฆญํ„ฐ๋ฅผ ๋”ฐ์™€์„œ ์ง์ ‘ ๋งŒ๋“ค์—ˆ๋‹ค.. ์ฒซ ํ”„๋กœ์ ํŠธ์ธ๋ฐ ๋„ˆ๋ฌด๋„ˆ๋ฌด๋„ˆ๋ฌด ๋ฟŒ๋“ฏํ•˜๋‹ค...! ๋ ˆ์ด์„œ๋ถ„๋“ค์ด ์ง์ ‘ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋„ˆ๋ฌด ์ข‹์„๊ฒƒ ๊ฐ™๋‹ค.
์ด๋ž˜์„œ ์ฝ”์น˜๋‹˜์ด ์‚ฌ๋žŒ๋“ค์ด ์“ธ๋งŒํ•œ๊ฑธ ๋งŒ๋“œ๋Š”๊ฒŒ ์ค‘์š”ํ•˜๋‹ค๊ณ  ํ•˜์…จ๊ตฌ๋‚˜ ๊นจ๋‹ฌ์•˜๋‹ค.
profile
์ƒˆ์‹น์ด

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 6์›” 21์ผ

๋„ˆ๋ฌด ์˜ˆ๋ป์š”!! ์—˜๋ฆฌ์Šค ๊ณต์‹ ์›นํŽ˜์ด์ง€ ๊ฐ™์•„์š”! ๋””์ž์ธ ๊ฐ๊ฐ๋„ ์žˆ์œผ์‹œ๊ณ , ์ฒ˜์Œ์ธ๋ฐ ๋„ˆ๋ฌด ์ž˜ ๋งŒ๋“œ์…”์„œ ๋ถ€๋Ÿฝ๋„ค์š”~

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ