-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
44 lines (31 loc) · 1.77 KB
/
Copy pathweather.js
File metadata and controls
44 lines (31 loc) · 1.77 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
$(document).ready(function(){
//pull location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
//make API request for weather at location from openweathermap
$.getJSON("https://api.wunderground.com/api/ca00d92ec76f700b/geolookup/q/" + position.coords.latitude +","+ position.coords.longitude +".json", function(forecast){
//assign name to #location
$("#location").html(forecast.location.city + ", " + forecast.location.state);
//getJSON request to weather underground
$.getJSON("https://api.wunderground.com/api/ca00d92ec76f700b/conditions/q/" + forecast.location.state + "/" + forecast.location.city + ".json", function(conditions){
//pull appropriate icon and assign to #weather-icon
$("#weather-icon").html("<img alt='current weather icon' class='img-responsive' src='https://icons.wxug.com/i/c/i/"+ conditions.current_observation.icon + ".gif'>")
//assign #skies based on result of weather.main & weather.description
$("#skies").html(conditions.current_observation.weather);
//convert main.temp to Fahrenheit and assign to #temp
$("#temp").html(conditions.current_observation.temp_f + " °F");
//assign #tempCelsius
$("#tempCelsius").html(conditions.current_observation.temp_c + " °C");
//assign #humidity
$("#humidity").html(conditions.current_observation.relative_humidity);
$("body").addClass(conditions.current_observation.weather);
})
//toggle button: Fahrenheit to Celsius using formula
$("button").click(function(){
$(".temperature p").toggle();
})
//});
});
});
}
});