-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (41 loc) · 1.41 KB
/
script.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
var latti,longi,api,weatherType,tempCacis,windSpeed,seaLevel,City,Country;
function getLocation(){
var tempKelvin,image;
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
latti = position.coords.latitude;
longi = position.coords.longitude;
api = 'https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/1f6bc0b490002ecbd8c2042affa687c3/'+latti+','+longi;
$.getJSON(api,function(data){
weatherType = data.weather[0].description;
$("#weat").text(weatherType);
weatherIcon = "http://openweathermap.org/img/w/"+data.weather[0].icon+".png";
image = $(document.createElement("img"));
image.attr('src',weatherIcon);
image.css({"width":"40px","height":"40px"});
$("#ico").html(image);
tempKelvin = data.main.temp;
tempCacis = (tempKelvin-273.15).toFixed(2)
$("#temp").text(tempCacis + " C");
windSpeed = data.wind.speed;
if (windSpeed >= 3 && windSpeed <= 5){
$("#clr-wind").addClass("success")
}
if (windSpeed < 3){
$("#clr-wind").addClass("info")
}
$("#windspd").text(windSpeed);
City = data.name;
Country = data.sys.country;
$("#city").text(City +", "+Country);
});
});
}
}
function fahren(){
var fah = (tempCacis * 9)/5 + 32;
$("#temp").text( fah + " F");
}
function celsi(){
$("#temp").text( tempCacis + " C");
}