-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript.js
More file actions
41 lines (32 loc) · 1.2 KB
/
Copy pathJavaScript.js
File metadata and controls
41 lines (32 loc) · 1.2 KB
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
const iconElement = document.querySelector(".weather-pic");
const tempElement = document.querySelector(".temp-degree");
const descElement = document.querySelector(".temp-desc");
const addressElement = document.querySelector(".address");
const notificationElement = document.querySelector(".notification");
const weather = {};
weather.temp = {
unit : "celsius"
}
const KELVIN = 273;
const API_KEY = "67764089c1e83a1cf40d9e50ec616f70";
if('geolocation' in navigator){
navigator.geolocation.getCurrentPosition(setPosition, showError);
}
else{
console.log("blocked");
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>';
}
function getWeather(latitude, longitude){
let api = 'http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=67764089c1e83a1cf40d9e50ec616f70';
console.log(api);
}