-
Notifications
You must be signed in to change notification settings - Fork 0
/
planebelly_backup.php
105 lines (99 loc) · 3.78 KB
/
planebelly_backup.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
<?php
/*
Flightaware.com FlightXML API Key: 25b79741e1f237b54522390c71981a50496d2b0e
*/
?>
<html>
<head>
<title>Flight Overhead</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.backstretch.min.js" type="text/javascript"></script>
<script type="text/javascript">
var map;
var planemarker = 'plane_marker.gif';
var latitude;
var longitude;
$(document).ready(function() {
$.backstretch("plane_belly.jpg", {speed: 150});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
getNearbyFlight();
});
}
else {
alert('Sorry, geolocation not possible');
}
});
function getNearbyFlight() {
var fxml_url = 'http://stml:25b79741e1f237b54522390c71981a50496d2b0e@flightxml.flightaware.com/json/FlightXML2/';
var minlat = latitude + 0.3;
var minlon = longitude - 0.4;
var maxlat = latitude - 0.3;
var maxlon = longitude + 0.4;
var query = '-latlong "'+minlat+' '+minlon+' '+maxlat+' '+maxlon+'"';
$.ajax({
type: 'GET',
url: fxml_url + 'Search',
data: { 'query': query, 'howMany': 10, 'offset': 0 },
success : function(result) {
$('.working').css("display","none");
$('#info').append('The nearest planes to you are:<br>');
for (var i in result.SearchResult.aircraft) {
var flight = result.SearchResult.aircraft[i];
var distance = calcDistance(flight.latitude, flight.longitude, latitude, longitude);
var bearing = calcBearing(latitude, longitude, flight.latitude, flight.longitude);
$('#info').append(distance+" miles to the "+bearing+": <a href='http://flightaware.com/live/flight/"+flight.ident+"' target='_blank'>"+flight.ident+"</a>, "+flight.origin+"→"+flight.destination+", heading "+flight.heading+"° at "+flight.groundspeed+"mph at "+flight.altitude+" feet.<br>");
}
},
error: function(data, text) { alert('Failed to fetch flight: ' + data); },
dataType: 'jsonp',
jsonp: 'jsonp_callback',
xhrFields: { withCredentials: true }
});
}
function calcDistance(startlat, startlon, endlat, endlon) {
// distance
var R = 6371; // km
var dLat = (endlat-startlat)*(Math.PI / 180);
var dLon = (endlon-startlon)*(Math.PI / 180);
var lat1 = (startlat)*(Math.PI / 180);
var lat2 = (endlat)*(Math.PI / 180);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
var totalDistanceInMiles = Math.round(d * 0.621371192);
return totalDistanceInMiles;
}
function calcBearing(lat1, lon1, lat2, lon2) {
var dLon = (lon2 - lon1);
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng1 = Math.atan2(y, x);
var brng2 = brng1 * 180 / Math.PI;
var brng3 = (brng2+360) % 360;
console.log(brng3);
if (brng3 >= 337.5 || brng3 < 22.5) { return 'North'; }
else if (brng3 >= 22.5 && brng3 < 67.5) { return 'Northeast'; }
else if (brng3 >= 67.5 && brng3 < 112.5) { return 'East'; }
else if (brng3 >= 112.5 && brng3 < 157.5) { return 'Southeast'; }
else if (brng3 >= 157.5 && brng3 < 202.5) { return 'South'; }
else if (brng3 >= 202.5 && brng3 < 247.5) { return 'Southwest'; }
else if (brng3 >= 247.5 && brng3 < 292.5) { return 'West'; }
else if (brng3 >= 292.5 && brng3 < 337.5) { return 'Northwest'; }
}
</script>
<style type="text/css">
* { margin: 0; padding: 0; }
body { width: 100%; height: 100%; text-align: center; }
#info { width: 650px; background: #fff; opacity: 0.75; moz-opacity: 0.75; padding: 25px; margin: 200px auto; }
</style>
</head>
<body>
<div id="info" class="ll">
<p class="working"><blink>working</blink></p>
</div>
</body>
</html>