async Task DisplaySatellite() { while (true) { closest = await SatelliteCalculations.FindClosestSatellite(userCoords.latitude, userCoords.longitude, userCoords.altitude); SatelliteName = closest.name; SatelliteDistance = closest.distance.ToString() + " km"; System.Threading.Thread.Sleep(100); } }
public MainPage() { InitializeComponent(); BindingContext = this; //GetMediaAsync(); closest = new Satellite("Oi, you need to click the button", 69); if (SatelliteCalculations.UpdateTLEData()) { IsFindVisible = true; } UserLatitude = userCoords.latitude; UserLongitude = userCoords.longitude; UserAltitude = userCoords.altitude; }
public static async Task <Satellite> FindClosestSatellite(double userLat, double userLong, double userHeight) { List <Tle> tleList = ParserTLE.ParseFile(pathToTLEData); Vector3 difference = new Vector3(0, 0, 0); Satellite closest = new Satellite("Temporary Satellite. If you see this, you done messed up", double.MaxValue); List <Satellite> satellites = new List <Satellite>(); One_Sgp4.Coordinate observer = new Coordinate(userLat, userLong, userHeight); for (int i = 0; i < tleList.Count; i++) { //Create Time points EpochTime startTime = new EpochTime(DateTime.UtcNow); EpochTime stopTime = new EpochTime(DateTime.UtcNow.AddHours(1)); One_Sgp4.Sgp4 sgp4Propagator = new Sgp4(tleList[i], Sgp4.wgsConstant.WGS_84); try { sgp4Propagator.runSgp4Cal(startTime, stopTime, 0.5); } catch { Console.WriteLine("Something went wrong with " + tleList[i].getName()); } List <One_Sgp4.Sgp4Data> resultDataList = new List <Sgp4Data>(); //Return Results containing satellite Position x,y,z (ECI-Coordinates in Km) and Velocity x_d, y_d, z_d (ECI-Coordinates km/s) resultDataList = sgp4Propagator.getResults(); try { double localSiderealTime = startTime.getLocalSiderealTime(observer.getLongitude()); Sgp4Data grrPoint = One_Sgp4.SatFunctions.getSatPositionAtTime(tleList[0], startTime, Sgp4.wgsConstant.WGS_84); One_Sgp4.Point3d sphCoordsSat = One_Sgp4.SatFunctions.calcSphericalCoordinate(observer, startTime, resultDataList[0]); double distance = sphCoordsSat.x; Satellite satellite = new Satellite(tleList[i].getName(), distance); satellites.Add(satellite); if (distance < closest.distance) { closest = satellite; } } catch { //Something went wrong with a satellite, skipped } } closest.distance = Math.Round(closest.distance, 2); return(closest); //Console.WriteLine("Done: " + satellites.Count + " satellites successfully analyzed from " + tleList.Count + " in the dataset."); //Console.WriteLine("The closest active satellite is " + closest.name.Trim() + " which is " + Math.Round(closest.distance, 2).ToString() + " kilometres away from you. Time: " + DateTime.Now.ToString("HH:mm:ss")); //Console.WriteLine(); }