Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (45 loc) · 1.99 KB
/
Copy pathapp.js
File metadata and controls
62 lines (45 loc) · 1.99 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let apiKey = "__API_KEY__";
console.log(apiKey);
function loadWeatherData(searchVal) {
fetch(`https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${searchVal}`)
.then(res => res.json())
.then(data => {
document.getElementById("root").innerHTML = `
<section>
<a href="#"
class="flex flex-col items-center bg-white border border-gray-200 rounded-lg shadow-sm md:flex-row md:max-w-xl hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700">
<img class="object-cover w-full rounded-t-lg h-96 md:h-auto md:w-48 md:rounded-none md:rounded-s-lg"
src="${data.current.condition.icon}" alt="">
<div class="flex flex-col justify-between p-4 leading-normal">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">${data.location.country}</h5>
<p class="mb-3 font-normal text-gray-700 dark:text-gray-400">${data.current.condition.text}</p>
<p class="mb-3 font-normal text-gray-700 dark:text-gray-400">${data.current.temp_c}</p>
<p class="mb-3 font-normal text-gray-700 dark:text-gray-400">${data.location.name}</p>
</div>
</a>
</section>
`
console.log(data);
})
}
function searchByCity() {
let searchVal = document.getElementById("txtSearchInput").value;
loadWeatherData(searchVal);
console.log(searchVal);
}
function getGeoLocation() {
navigator.geolocation.getCurrentPosition(showPosition);
}
function showPosition(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
loadWeatherData(position.coords.latitude + "," + position.coords.longitude);
}
getGeoLocation();
// let showPosition = function (position){
// console.log(position);
// }
// let showPosition = (position) => {
// console.log(position);
// }
// let showPosition = position => console.log(position);