Skip to content

Commit

Permalink
8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixtr committed Feb 4, 2024
1 parent 3fefde3 commit 9f216ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ <h1 class="hidden" id="greeting"></h1>
<span></span>
<span></span>
</div>
<div id="weather">
<span></span>
<span></span>
</div>
<script src="js/greetings.js"></script>
<script src="js/clock.js"></script>
<script src="js/quotes.js"></script>
Expand Down
15 changes: 12 additions & 3 deletions js/js/weather.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
const weather = document.querySelector("#weather span:first-child");
const city = document.querySelector("#weather span:last-child");
const API_KEY = "241051bf13976dd3ddf8b8d9f247255e";

function onGeoOk(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
console.log("You live in", lat, lng);
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) => {
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);

0 comments on commit 9f216ef

Please sign in to comment.