2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Weather.php');
5 require_once('require/class.METAR.php');
6 $Spotter = new Spotter();
7 if (isset($_GET['download']))
9 header('Content-disposition: attachment; filename="weather.json"');
11 header('Content-Type: text/javascript');
12 $latitude = filter_input(INPUT_GET
,'latitude',FILTER_SANITIZE_NUMBER_FLOAT
,FILTER_FLAG_ALLOW_FRACTION
);
13 $longitude = filter_input(INPUT_GET
,'longitude',FILTER_SANITIZE_NUMBER_FLOAT
,FILTER_FLAG_ALLOW_FRACTION
);
14 if ($latitude == '' ||
$longitude == '') return '';
15 //echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
16 $airports = $Spotter->closestAirports($latitude,$longitude,300);
19 $Weather = new Weather();
23 if (empty($airports)) $ew = false;
25 $met = $METAR->getMETAR($airports[$i]['icao']);
28 $parsed = $METAR->parse($met[0]['metar']);
31 if (isset($parsed['temperature'])) {
32 $rain = array_merge($rain,array('temp' => $parsed['temperature']));
34 if (isset($parsed['rh'])) {
35 $rain = array_merge($rain,array('rh' => $parsed['rh']));
37 if (isset($parsed['weather']) && $parsed['weather'] == 'CAVOK') {
38 echo json_encode(array('clouds' => array(),'rain' => array()));
41 } elseif (isset($parsed['cloud'])) {
42 $result = $Weather->buildcloudlayer($parsed);
43 if (!empty($result)) {
46 echo json_encode(array('clouds' => $result,'rain' => $rain));
53 if ($i >= count($airports)) $ew = false;
55 if ($dtf === false) echo json_encode($Weather->openweathermap($latitude,$longitude));