A flight path on a real map is a great way to see how that visual approach actually went. GPX is a simple text format that most mapping tools read, so it's an easy thing to produce yourself.
Use the project file from the 2020 SimConnect starter.
The recorder
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.FlightSimulator.SimConnect;
using var ready = new EventWaitHandle(false, EventResetMode.AutoReset);
using var sim = new SimConnect("Track recorder", IntPtr.Zero, 0, ready, 0);
var points = new StringBuilder();
var running = true;
Console.CancelKeyPress += (_, e) => { e.Cancel = true; running = false; };
foreach (var (name, unit) in new[] { ("PLANE LATITUDE", "degrees"), ("PLANE LONGITUDE", "degrees"), ("PLANE ALTITUDE", "meters") })
{
sim.AddToDataDefinition(Id.Track, name, unit, SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
}
sim.RegisterDataDefineStruct<Point>(Id.Track);
sim.OnRecvSimobjectData += (_, data) =>
{
var p = (Point)data.dwData[0];
// The main menu reports a spot at zero, zero. Leave it out of the track.
if (Math.Abs(p.Latitude) < 0.01 && Math.Abs(p.Longitude) < 0.01)
{
return;
}
points.AppendLine(string.Create(CultureInfo.InvariantCulture,
$"<trkpt lat=\"{p.Latitude:F6}\" lon=\"{p.Longitude:F6}\"><ele>{p.Altitude:F1}</ele><time>{DateTime.UtcNow:yyyy-MM-ddTHH:mm:ssZ}</time></trkpt>"));
};
sim.OnRecvQuit += (_, _) => running = false;
// interval 4 skips four seconds between points, so you get one every five.
sim.RequestDataOnSimObject(Id.Track, Id.Track, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 4, 0);
Console.WriteLine("Recording. Press Ctrl+C to save.");
while (running)
{
if (ready.WaitOne(500))
{
sim.ReceiveMessage();
}
}
var file = $"flight-{DateTime.Now:yyyyMMdd-HHmm}.gpx";
File.WriteAllText(file, $"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx version=\"1.1\" creator=\"Track recorder\" xmlns=\"http://www.topografix.com/GPX/1/1\"><trk><trkseg>\n{points}</trkseg></trk></gpx>\n");
Console.WriteLine($"Saved {file}");
enum Id { Track }
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Point
{
public double Latitude, Longitude, Altitude;
}
