-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
75 lines (53 loc) · 2.54 KB
/
script.js
File metadata and controls
75 lines (53 loc) · 2.54 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var user_location;
function getData() {
user_location = $("#searchleft").val();
if(user_location==""){
alert("Enter location first!")
return false
}
$.ajax({
url: "https://api.weatherapi.com/v1/forecast.json?key=ad1f01cca57f40b2909103412232604&q="+user_location,
success: function(data) {
console.log(data);
let location = data.location.name+", "+data.location.region;
let temp = data.current.temp_c;
let condition = data.current.condition.text;
let humidity = data.current.humidity+"%";
let wind = data.current.wind_kph+"Km/h"+" "+data.current.wind_degree+"°"+" "+data.current.wind_dir;
let pressure = data.current.pressure_mb+"mb";
let visibility = data.current.vis_km+"Km";
localStorage.setItem('user_location',location);
let original_url = "https:"+data.current.condition.icon;
let weather_icon = original_url.replace("64x64", "128x128");
let temp_high = data.forecast.forecastday[0].day.maxtemp_c;
let temp_low = data.forecast.forecastday[0].day.mintemp_c;
$(".location").html('<span id="location_icon" class="material-icons">location_on</span> '+location);
$("#temperature").html(temp+"°C");
$(".temp_high").html("High : "+temp_high+"°C | ");
$(".temp_low").html("Low : "+temp_low+"°C");
$("#weather-description").html(condition);
$("#weather_icon").attr("src",weather_icon);
$(".Wind").html("Wind : "+wind);
$(".Pressure").html("Pressure : "+pressure);
$(".Humidity").html("Humidity : "+humidity);
$(".Visibility").html("Visibility : "+visibility);
$(".main-container").show('slow');
}
})
}
function checkWeather(){
var saved_location = localStorage.getItem('user_location');
if(saved_location!=null){
//alert(saved_location)
//user_location==saved_location;
$("#searchleft").val(saved_location);
getData();
$(".button-2").show();
}
}
function deleteSavedLocation(){
if (confirm("Do you want to delete saved location?")) {
localStorage.removeItem('user_location');
window.location.reload();
}
}