-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
120 lines (103 loc) · 4.31 KB
/
index.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php include_once('./header.php'); ?>
<?php include_once('./subnav.php'); ?>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.0.2/jquery.simpleWeather.min.js"></script>
<script>
function getCurrent() {
var lat = 0;
var lon = 0;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById("data").innerHTML = "Finding closest weather station...";
lat = position.coords.latitude;
lon = position.coords.longitude;
$.getJSON("currentData.php?latitude=" + lat + "&longitude=" + lon, function(data){
console.log(data);
if (data.error === "far") {
$.simpleWeather({
location: lat+","+lon,
unit: 'f',
success: function(data) {
console.log(data);
$("#data").html("<p>Temperature: "+data.temp+"° F</p>");
$("#data").append("<p>Humidity: "+data.humidity+"%</p>");
$("#data").append("<p>Pressure: "+data.pressure+" "+data.units.pressure+"</p>");
$("#data").append("<p>Wind speed: "+data.wind.speed+" mph</p>");
},
error: function(error) {
$("#data").html('<p>'+error+'</p>');
}
});
} else {
$("#data").html("<p>Temperature: "+data.temp+"° F</p>");
$("#data").append("<p>Humidity: "+data.humidity+"%</p>");
$("#data").append("<p>Pressure: "+data.pressure+" mbars</p>");
$("#data").append("<p>Light: "+data.light+" lux</p>");
$("#data").append("<p>Wind speed: "+data.wind+" mph</p>");
$("#data").append("<p>ZIP code: "+data.zipcode+"</p>");
if (data.light > 20) {
if(data.humidity > 60) {
$('#rain').show();
} else if(data.humidity > 30) {
$('#cloudy').show();
} else {
$('#sun').show();
}
} else {
$('#moon').show();
}
}
});
});
}
}
function getForecast() {
var lat = 0;
var lon = 0;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
$.simpleWeather({
location: lat+","+lon,
unit: 'f',
success: function(data) {
console.log(data);
$("#forecast").html("<p>Forecast for: "+data.city+", "+data.region+" on "+data.forecast[1].date);
$("#forecast").append("High temperature: "+data.forecast[1].high+"° F<br>");
$("#forecast").append("Low temperature: "+data.forecast[1].low+"° F<br>");
$("#forecast").append(""+data.forecast[1].text+"</p>");
$("#forecast").append("<p>Forecast on "+data.forecast[2].date);
$("#forecast").append("High temperature: "+data.forecast[2].high+"° F<br>");
$("#forecast").append("Low temperature: "+data.forecast[2].low+"° F<br>");
$("#forecast").append(""+data.forecast[2].text+"</p>");
},
error: function(error) {
$("#forecast").html('<p>'+error+'</p>');
}
});
});
}
}
</script>
<p id="test"></p>
<div id="content" class="content">
<h1>
Welcome! Personal Pi in the Sky
</h1>
<script type="text/javascript">
getCurrent();
getForecast();
</script>
<p><span id="data">Getting current location...</span></p>
<img id="sun" src="weathericons/sun.png" style="width:50px;height:50px;display:none">
<img id="moon" src="weathericons/moon.png" style="width:50px;height:50px;display:none">
<img id="rain" src="weathericons/rain.png" style="width:50px;height:50px;display:none">
<img id="cloudy" src="weathericons/cloudy.png" style="width:50px;height:50px;display:none">
<p><span id="forecast">Finding forecast...</span></p>
<p>
<br>
Personal Pi in the Sky was created by Purdue University Computer Science students
as part of a semester long software engineering class. To learn more about the class and our team, see the About Us page on our website.<br><br>
</p>
</div>
<?php include_once('./footer.php'); ?>