-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (29 loc) · 1.09 KB
/
app.js
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
// Tutorial by http://youtube.com/CodeExplained
// api key : 82005d27a116c2880c8f0fcb866998a0
const iconElement = document.querySelector(".weather-icon");
const tempElement = document.querySelector(".temperature-value p");
const descElement = document.querySelector(".temperature-description p");
const locationElement = document.querySelector(".location p");
const notificationElement = document.querySelector(".notification");
const weather={};
weather.temperature={
unit:"celsius"
}
const KELVIN = 273;
const key ="82005d27a116c2880c8f0fcb866998a0";
if('geolocation' in navigator){
navigator.geolocation.getCurrentPosition(setPosition,showError);
}else{
notificationElement.style.display="block"
notificationElement.innerHTML="<p>Browser doesn't Support Geolocation</p>";
}
function setPosition(position){
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
getWeather(latitude,longitude);
}
function showError(error){
notificationElement.style.display="block";
notificationElement.innerHTML=`<p> ${error.message}</p>`;
}
//get weather