-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.html
105 lines (84 loc) · 2.35 KB
/
index.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="" />
<meta name="author" content="">
</head>
<body>
<h1>Forecast.io JS API</h1>
<h2>Current Temperatures</h2>
<ul id="currentTemp"></ul>
<hr>
<h2>Forecast for today</h2>
<ul id="itemList"></ul>
<hr>
<h2>Forecast for the week</h2>
<ul id="itemList2"></ul>
<script src="require.js"></script>
<!-- <script src="forecast.io.js"</script> -->
<script>
var ForecastIO = require(['forecast.io'], function(ForecastIO) {
//This function is called when scripts/helper/util.js is loaded.
//If util.js calls define(), then this function is not fired until
//util's dependencies have loaded, and the util argument will hold
//the module value for 'helper/util'.
/*
* EXAMPLE LOCATION DATA
*/
var locations = [
{
latitude: '52.4308',
longitude: '13.2588'
},
{
latitude: '22.4308',
longitude: '3.2588'
}
];
//Single object example
// var locations = {
// latitude: '52.4308',
// longitude: '13.2588'
// };
var forecast = new ForecastIO({
PROXY_SCRIPT: 'proxy.php'
});
/*
* GET CURRENT CONDITIONS
*/
forecast.getCurrentConditions(locations, function(conditions) {
var items = '';
// echo temperature
for (var i = 0; i < conditions.length; i++) {
items += '<li>' + conditions[i].getTemperature() + '</li>';
}
document.getElementById('currentTemp').innerHTML = items;
});
/*
* GET HOURLY CONDITIONS FOR TODAY
*/
forecast.getForecastToday(locations, function(conditions) {
var items = '';
for (var i = 0; i < conditions.length; i++) {
items += '<li>' + conditions[i].getTime('HH:mm') + ': ' + conditions[i].getTemperature() + '</li>';
}
document.getElementById('itemList').innerHTML = items;
});
/*
* GET DAILY CONDITIONS FOR NEXT 7 DAYS
*/
forecast.getForecastWeek(locations, function(conditions) {
var items2 = '';
for (var i = 0; i < conditions.length; i++) {
items2 += '<li>' + conditions[i].getTime('YYYY-MM-DD') + ': ' + conditions[i].getMaxTemperature() + '</li>';
}
document.getElementById('itemList2').innerHTML = items2;
});
});
</script>
</body>
</html>