-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
37 lines (25 loc) · 1.04 KB
/
index.ts
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
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function getWeather(coords) {
var url = "https://api.darksky.net/forecast/a5ea3a75b7361771323e8adc14b09b66/"
+ coords + "?exclude=minutely,hourly,flags" + "&units=si" + "&callback=?";
$.getJSON(url, function(json) {
document.getElementById('weather').innerHTML= 'The weather is'+' ' + json.currently["apparentTemperature"];
});
}
function success(pos) {
var crd = pos.coords;
var coords = crd.latitude+','+ crd.longitude;
getWeather(coords);
document.getElementById('welcome').innerHTML='Your Current Location is:';
document.getElementById('latitude').innerHTML=`Latitude: ${crd.latitude}`
document.getElementById('longitude').innerHTML=`Longitude: ${crd.longitude}`
console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);