Skip to content

Commit

Permalink
Merge pull request #12 from saiashishanshuman1/main
Browse files Browse the repository at this point in the history
Weather API #4
  • Loading branch information
Aniket762 authored Aug 5, 2021
2 parents 9f8efaa + 2edb477 commit 3ff4d8a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# API-directory
Task given to our talented members
# Weather-APP
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel = "stylesheet" href = "./style.css" />
<title>Weather</title>
</head>
<body>
<div class="location">
<h1 class="location-timezone">TimeZone </h1>
<p><img id="wicon" src="http://openweathermap.org/img/w/05d.png" alt="Weather Icon" width="100" height="100"></p>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temperature-degree">34</h2>
<span>°C</span>
</div>
<div class="temperature-description">Its frgging cold</div>
</div>
<script src="index.js">

</script>

</body>
</html>
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
window.addEventListener('load', () => {
let long;
let lat;
let temperatureDescription = document.querySelector('.temperature-description');
let temperatureDegree = document.querySelector('.temperature-degree');
let locationTimezone = document.querySelector('.location-timezone');
let iconcode
let iconurl



if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(position =>{
long = position.coords.longitude;
lat = position.coords.latitude;

const api =`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&units=metric&appid=b63b7edcb5598e3d9b7bdfdecf2600c3
`;

fetch(api)
.then(response =>{
return response.json();
})
.then(data => {
console.log(data);
const{temp} = data.main;
temperatureDegree.textContent = data.main.temp;
temperatureDescription.textContent = data.weather[0].description;
locationTimezone.textContent = data.name;
iconcode = data.weather[0].icon;
iconurl = "http://openweathermap.org/img/w/" + iconcode + ".png";
document.getElementById("wicon").src = iconurl
console.log(document.getElementById("wicon").src)







});
});
}


});
42 changes: 42 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

body{
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
background: radial-gradient(circle, rgba(238,174,202,1) 0%, rgba(148,187,233,1) 100%);
font-family: sans-serif;
color: white;

}
.location,
.temperature{
height: 40vh ;
width: 60%;
display: flex;
justify-content: space-around;
align-items: center;
color: black;
}
.temperature{
flex-direction: column;
}
.degree-section{
display: flex;
align-items: center;
cursor: pointer;
}
.degree-section span{
margin: 10px;
font-size: 30px;
}
.degree-section h2{
font-size: 40px;
}

0 comments on commit 3ff4d8a

Please sign in to comment.