-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.html
193 lines (176 loc) · 7.03 KB
/
weather.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="shortcut icon" href="icoder/code.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Bitter:ital@1&display=swap" rel="stylesheet">
<title>icoder</title>
<style>
#loc-search{
width:25%;
margin-inline: auto;
margin-top: 2rem;
border:none;
border-bottom:1px solid rgba(0,0,0,0.2);
}
body{
background: linear-gradient(to right,#ff5f6d, #ffc371);
font: 1rem/1.3 "Roboto", sans-serif
}
#icon
{
width:125px;
height:125px;
}
#weather-card
{
margin:auto;
margin-top:2em;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
border-radius:1em;
overflow: auto;
background-image: linear-gradient(to bottom, #9796f0,#fbc7d4);
color:white;
}
p{
font-size:1em;
}
#temp-value{
/* font-family: 'Bitter', serif; */
font-size:2em;
}
p,h3{
font-size: 25px;
text-transform: uppercase;
text-align:center;
}
h3,span{
margin-top:8px;
font-size:2em;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="/index.html">iCoder</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="icoder/index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="icoder/todolist.html">TO do list</a>
</li>
<li class="nav-item">
<a class="nav-link" href="icoder/weather.html">WEATHER</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Games
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Tic Toe</a></li>
<li><a class="dropdown-item" href="#">Snake</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
<button type="button" class="btn btn-outline-primary login">Login</button>
<button type="button" class="btn btn-outline-danger login ">Sign up</button>
</div>
</div>
</nav>
<div class="container">
<input id="loc-search"class="form-control" type="search" placeholder="Weather in your city" aria-label="Search">
<div id="weather-card" class="card" style="width: 18rem;">
<h3 id ="location" class="card-title ">-------</h3>
<hr>
<p class="card-text "><span id="temp-value">--------</span><sup>℃</sup></p>
<img id="icon" src="#" alt="Card image cap">
<div class="card-body">
<p id="condition" class="card-text ">------</p>
</div>
</div>
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script >
console.log("hi");
const api = "70c74ccb3c1e3030150ac713037778ec";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
// Storing Longitude and Latitude in variables
long = position.coords.longitude;
lat = position.coords.latitude;
const base = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=${api}&units=metric`;
// Using fetch to get data
fetch(base)
.then((response) => {
return response.json();
})
.then((data) => {
// const temp_min = data.main.temp_min;
// const temp_max = data.main.temp_max;
const temp = data.main.temp;
const place = data.name;
const { description, icon } = data.weather[0];
console.log(description);
document.getElementById("location").innerText = place;
document.getElementById("temp-value").innerText = temp;
document.getElementById("condition").innerText = `${description}`;
document.getElementById("icon").src=`http://openweathermap.org/img/wn/${icon}@2x.png`;
});
});
}
document.getElementById("loc-search").addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
update();
}
});
function update(){
let cityname = document.getElementById("loc-search").value;
document.getElementById("loc-search").value = "";
cityname.replace(/ /g, "");
if (cityname != "") {
const base1 = `https://api.openweathermap.org/data/2.5/weather?q=${cityname}&appid=${api}&units=metric`;
fetch(base1)
.then((response) => {
return response.json();
})
.then((data) => {
// const temp_min = data.main.temp_min;
// const temp_max = data.main.temp_max;
const temp = data.main.temp;
const place = data.name;
const { description, icon } = data.weather[0];
document.getElementById("location").innerText = place;
document.getElementById("temp-value").innerText = temp;
document.getElementById("condition").innerText = `${description}`;
document.getElementById("icon").src=`http://openweathermap.org/img/wn/${icon}@2x.png`;
});
}
}
</script>
</html>