Skip to content

Commit da6a7d2

Browse files
authored
Merge pull request sanscript-tech#393 from Mukulbaid63/aqi_1
AQI Detector added
2 parents 4871b44 + 68faab1 commit da6a7d2

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

JavaScript/AqiDetector/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## AQI Detector:
2+
- This script built in Javascript is a AQI Detector.
3+
- The script automatically detects the location of the current city or the nearest city.
4+
- If the browser supports the geolocation feature, it didplays AQI and the location,else error message is displayed.
5+
![Image](capture.JPG)
6+
- Output of the script.

JavaScript/AqiDetector/app.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var temp = {
2+
key: "943422edf7ee41eb9b0ba3854e628f08 ",
3+
base: "https://api.weatherbit.io/v2.0/current/airquality?"
4+
}
5+
var notificationElement = document.querySelector(".notification");
6+
if (navigator.geolocation) {
7+
navigator.geolocation.getCurrentPosition(setPosition);
8+
notificationElement.innerHTML = "";
9+
10+
}
11+
else {
12+
notificationElement.innerHTML = "Geolocation is not supported by this browser.";
13+
}
14+
function setPosition(position){
15+
let latitude = position.coords.latitude;
16+
let longitude = position.coords.longitude;
17+
console.log(latitude);
18+
console.log(longitude);
19+
getAQI(latitude, longitude);
20+
}
21+
function getAQI(lat,lon) {
22+
fetch(`${temp.base}lat=${lat}&lon=${lon}&units=metric&key=${temp.key}`)
23+
.then(aqi => {
24+
return aqi.json();
25+
}).then(displayResults);
26+
}
27+
function displayResults(aq){
28+
let aqi=document.querySelector(".aqi");
29+
aqi.innerHTML=`${aq.data[0].aqi}`;
30+
let location=document.querySelector(".location");
31+
location.innerHTML=`${aq.city_name},${aq.country_code}`
32+
}

JavaScript/AqiDetector/capture.JPG

53 KB
Loading

JavaScript/AqiDetector/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3+
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4+
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5+
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
6+
<html>
7+
<head>
8+
<meta charset="utf-8">
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10+
<title>AQI DETECTOR</title>
11+
<meta name="description" content="">
12+
<meta name="viewport" content="width=device-width, initial-scale=1">
13+
<link rel="stylesheet" href="style.css">
14+
</head>
15+
<body>
16+
<h1>AQI DETECTOR</h1>
17+
18+
<div class="notification"></div>
19+
<div class="loc">Your Current Location:<span class="location"></span></div>
20+
<div class="aq">The AQI is:<span class="aqi"></span> micrograms per cubic meter (µg/m3)</div>
21+
22+
<script src="app.js"></script>
23+
</body>
24+
</html>

JavaScript/AqiDetector/style.css

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
body{
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
6+
}
7+
.notification{
8+
9+
font-size: 20px;
10+
}
11+
.loc{
12+
margin: 10px;
13+
padding: 15px;
14+
font-size: 30px;
15+
}
16+
.aq{
17+
margin: 10px;
18+
padding: 15px;
19+
font-size: 30px;
20+
}
21+
h1{
22+
border-bottom: 3px black solid;
23+
}
24+
.aqi{
25+
font-weight: 700;
26+
}
27+
.location{
28+
font-weight: 500;
29+
}

0 commit comments

Comments
 (0)