Last active
April 15, 2024 17:23
-
-
Save shupp/1741086 to your computer and use it in GitHub Desktop.
Real Time ISS Location Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('America/Los_Angeles'); | |
require_once 'Predict.php'; | |
require_once 'Predict.php'; | |
require_once 'Predict/Sat.php'; | |
require_once 'Predict/QTH.php'; | |
require_once 'Predict/Time.php'; | |
require_once 'Predict/TLE.php'; | |
// San Francisco is the observing location, which is required | |
$qth = new Predict_QTH(); | |
$qth->lat = 37.790252; // Latitude North | |
$qth->lon = -122.419968; // Longitude East | |
// The iss.tle file is the first 3 lines of | |
// http://celestrak.com/NORAD/elements/stations.txt | |
// Make sure you update this content, it goes out of date within a day or two | |
$tleFile = file('iss.tle'); // Load up the ISS data file from NORAD | |
$tle = new Predict_TLE($tleFile[0], $tleFile[1], $tleFile[2]); // Instantiate it | |
$sat = new Predict_Sat($tle); // Load up the satellite data | |
$now = Predict_Time::get_current_daynum(); // get the current time as Julian Date (daynum) | |
// Calculate the current location of the satellite | |
$predict = new Predict(); | |
$predict->predict_calc($sat, $qth, $now); | |
$kph = $sat->velo * 60 * 60; | |
$mph = $kph * Predict::km2mi; | |
$zone = new DateTimezone('America/Los_Angeles'); | |
$date = new DateTime(); | |
$date->setTimezone($zone); | |
$date->setTimestamp(Predict_Time::daynum2unix($now)); | |
$time = $date->format('m-d-Y g:i:s a T'); | |
// Output data | |
echo "ISS Current Position: \n\n"; | |
echo " Latitude: " . $sat->ssplat . "\n"; | |
echo " Longitude: " . $sat->ssplon . "\n"; | |
echo " Altitude: " . number_format($sat->alt * Predict::km2mi, 2) . ' miles up' . "\n"; | |
echo " Velocity: " . number_format($mph, 2) . " mph\n"; | |
echo " Date/Time: " . $time . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment