-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weathercaster.js
91 lines (70 loc) · 3.1 KB
/
Weathercaster.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
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
function closeDialog() { // closes dialog box
document.getElementById("locationAsk").close();
}
function display_refresh(){ // refresh func for time and date
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_time()',refresh)
}
function display_time() { // sets up time
var start_time = new Date() // Imports date
var hours = start_time.getHours().toString()
hours = hours.length==1 ? " " + hours : hours; // Adds leading space if neccesary
var minutes = start_time.getMinutes().toString()
minutes = minutes.length==1 ? 0 + minutes : minutes; // Adds leading zero if neccesary
var good_time = hours + ":" + minutes; // Makes time string
document.getElementById('time').innerHTML = good_time; // Assigns string
display_refresh(); // Refreshes
}
function display_date() { // sets up date
var start_date = new Date() // Imports date
const months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var month = start_date.getMonth();
month = months[month]
const dates = ["1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st","32nd"];
var date = start_date.getDate();
date = dates[date]
const weekdays = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var day = start_date.getDay();
day = weekdays[day]
var good_date = day + ", " + month + " " + date; // Makes date string
document.getElementById('date').innerHTML = good_date; // Assigns string
display_refresh(); // Refreshes
}
//function weather() {
//
// var location = document.getElementById("location");
// var apiKey = 'api key';
// var url = 'https://api.forecast.io/forecast/';
//
// navigator.geolocation.getCurrentPosition(success, error);
//
// function success(position) {
// latitude = position.coords.latitude;
// longitude = position.coords.longitude;
//
// location.innerHTML = 'Latitude is ' + latitude + '° Longitude is ' + longitude + '°';
//
// $.getJSON(url + apiKey + "/" + latitude + "," + longitude + "?callback=?", function(data) {
// $('#temp').html(data.currently.temperature + '° F');
// });
// }
//}
function weather() {
var location = document.getElementById("location");
var apiKey = 'INSERT API KEY';
var url = 'https://api.forecast.io/forecast/';
navigator.geolocation.getCurrentPosition(success, error);
function success(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
location.innerHTML = 'Latitude is ' + latitude + '° Longitude is ' + longitude + '°';
$.getJSON(url + apiKey + "/" + latitude + "," + longitude + "?callback=?", function(data) {
$('#temp').html(data.currently.temperature + '° F');
$('#minutely').html(data.minutely.summary);
});
}
function error() {
location.innerHTML = "Unable to retrieve your location";
}
location.innerHTML = "Locating...";
}