-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (50 loc) · 1.57 KB
/
index.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
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
// -----------THIS FILE IS ONLY FOR LEARNING PART-------------
console.log('Hello Tanisha!');
const API_key = '12f58fd1166be5fc552fb2ac2665269c';
function renderWeatherInfo(data){
//UI m mapping
let newPara = document.createElement('p');
newPara.textContent = `${data?.main?.temp.toFixed(2)} C`;
document.body.appendChild(newPara);
}
async function showWhether(){
try{
let city='goa';
const response = await fetch(`https://api.openweathe map.org/data/2.5/weather?q=${city}&appid=${API_key}&units=metric`);
let data = await response.json();
console.log("weather data" , data);
renderWeatherInfo(data);
}
catch(err){
//handle the error here.
}
}
// showWhether();
async function getCustomWeatherDetails(){
try{
let latitude = 15.6333;
let longitude = 18.3333;
let result = await fetch(`https://api.openweathermap.org/data/2.5/weather?${latitude}&${longitude}&appid=${API_key}&units=metric`);
let data =await result.json();
console.log(data);
}
catch(err){
console.log("Error Found!");
}
}
//adding my location using geolocation API
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}
else{
console.log("no geolocation support");
}
}
function showPosition(position){
let lati=position.coords.latitude;
let longi=position.coords.longitude;
// let para=document.createElement("p");
// para.textContent=
console.log(lati ," ", longi);
}