-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent.html
144 lines (104 loc) · 5.19 KB
/
current.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body style="background:url('curfinal.jpg');background-repeat: no-repeat;background-size: cover;">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
</div>
<ul class="nav navbar-nav">
<li class="active" style="color: mintcream;" ><a href="index.html">Home</a></li>
<li class="active"><a href="worldlive.html">Get world live data</a></li>
<li class="active" ><a href="current.html">Get Covid data of your current location</a></li>
<li class="active" ><a href="globe.html">Covid-19 Global tracker</a></li>
<li class="active" ><a href="local.html">Covid-19 Indian State tracker</a></li>
<li class="active" ><a href="district.html">Covid-19 Indian city/district tracker</a></li>
</ul>
</div>
</nav>
<h1 class="text-center" style="color: rgb(0, 0, 0);">Fetching your current location and covid data<img src="location.jpg" height="46px" width="54px"><img src="covid.png" height="46px" width="54px"></h1>
<h3 class="text-center" id="Lat" style="color: rgb(243, 33, 33);"> </h3>
<h3 class="text-center" id="long" style="color: rgb(247, 19, 19);"> </h3>
<h3 class="text-center" id="State" style="color: rgb(34, 34, 221);"> </h3>
<h3 class="text-center" id="City" style="color: rgb(19, 165, 50);"> </h3>
<h3 class="text-center" id="active" style="color: rgb(196, 25, 159);"> </h3>
<h3 class="text-center" id="confirmed" style="color: rgb(248, 125, 24);"> </h3>
<h3 class="text-center" id="deceased" style="color: rgb(0, 205, 219);"> </h3>
<h3 class="text-center" id="recovered" style="color: rgb(250, 54, 113);"> </h3>
</body>
<script>
function getCoordintes() {
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
var lat = crd.latitude.toString();
var lng = crd.longitude.toString();
var coordinates = [lat, lng];
console.log(`Latitude: ${lat}, Longitude: ${lng}`);
getCity(coordinates);
return;
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);
}
// Step 2: Get city name
function getCity(coordinates) {
let xhr = new XMLHttpRequest();
let lat = coordinates[0];
let lng = coordinates[1];
// Paste your LocationIQ token below.
xhr.open('GET', "https://us1.locationiq.com/v1/reverse.php?key=pk.0726277d645e72ab440b7fad10c021e1&lat=" +
lat + "&lon=" + lng + "&format=json", true);
xhr.send();
xhr.onreadystatechange = processRequest;
xhr.addEventListener("readystatechange", false);
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
response = JSON.parse(xhr.responseText);
let state=response.address.state;
let city = response.address.city;
console.log(city);
console.log(state);
var url="https://api.covid19india.org/state_district_wise.json"
fetch(url)
.then((res)=>res.json())
.then((res)=> {
console.log(res[state].districtData[city].deceased)
var Lat=document.getElementById('Lat')
var long=document.getElementById('long')
var State=document.getElementById('State')
var City=document.getElementById('City')
var active=document.getElementById('active')
var confirmed=document.getElementById('confirmed')
var recovered=document.getElementById('recovered')
var deceased=document.getElementById('deceased')
Lat.append("Latitude: "+lat)
long.append("Longitude: "+lng)
State.append("State: "+state)
City.append("City/district: "+city)
active.append("Active Cases: "+(res[state].districtData[city].active))
confirmed.append("Total confirmed: "+(res[state].districtData[city].confirmed))
recovered.append("Total recovered: "+(res[state].districtData[city].recovered))
deceased.append("Total deaths: "+(res[state].districtData[city].deceased))
})
return;
}
}
}
getCoordintes();
</script>
</html>