Jump to content
The simFlight Network Forums

Distance Flown


Recommended Posts

Hi,

I use VB.NET How Can I obtain the distance flown? For expample. I take-off from Heatrow and I land at Chicago O`Hare. I want to obtain the distance flown in the flight. But I want to see the always the distance flown, not only when I arrival. If I am in the middle of the Atlantic I want to see the distance flown too. I want to see the distance flown anywhere. I don´t found any offset to do this.

Link to comment
Share on other sites

I use VB.NET How Can I obtain the distance flown? For expample. I take-off from Heatrow and I land at Chicago O`Hare. I want to obtain the distance flown in the flight. But I want to see the always the distance flown, not only when I arrival. If I am in the middle of the Atlantic I want to see the distance flown too. I want to see the distance flown anywhere. I don´t found any offset to do this.

There isn't one, that's why. It isn't something supplied by FS You'd have to compute it by reading the latitudes and longitudes and doing the trig at regular intervals.

Pete

  • Upvote 1
Link to comment
Share on other sites

My DLL will do the trigonometry for you:

Create a new fsLatLonPoint class from the current position, then get the distance from another fsLonLatPoint (the previous measured position) using one of the DistanceFrom... methods.

The fsLatLonPoint takes in an fsLatitude and fsLongitude class to define the location. These two classes can be given the raw 8-byte values from the Lat and Lon offsets in FSUIPC, so you don't even need to convert them to degrees or anything.

For more details and examples, see the UserGuide.pdf:

"Reading and Displaying Longitudes and Latitudes" on Page 15 and

"Distances and Bearings between Two Points" on Page 17

Paul

  • Upvote 1
Link to comment
Share on other sites

Ok, I read the User Guide. But, I have a problem. I want to calculate the distance flown from the start position (position when I connect with the simulator) to current position.

I tryed it:


Public Class MainForm

'Some Code
Dim StartPoint As FsLatLonPoint

' Initialise some of the variables we will need later
Public Sub New()
InitializeComponent()
Dim StartLat As FsLatitude = New FsLatitude(Latitude.Value)
Dim StartLon As FsLongitude = New FsLongitude(Longitude.Value)
StartPoint = New FsLatLonPoint(StartLat, StartLon)
End Sub
[/CODE]

And in the timer this:

[CODE]
Dim Lat As FsLatitude = New FsLatitude(Latitude.Value)
Dim Lon As FsLongitude = New FsLongitude(Longitude.Value)
Dim Lat2 As Double = (Latitude.Value * 90.0 / (10001750.0 * 65536.0 * 65536.0))
Me.LatitudeBox.Text = Lat.ToString()
Me.LongitudeBox.Text = Lon.ToString()
'Distance Flown
Dim CurrentPosition As FsLatLonPoint = New FsLatLonPoint(Lat, Lon)
Dim distance As Double = 0
Select Case (Me.FlownUnitsCombo.Text)
Case "Nautical Miles"
distance = CurrentPosition.DistanceFromInNauticalMiles(StartPoint)
Case "Statute Miles"
distance = CurrentPosition.DistanceFromInFeet(StartPoint) / 5280D
Case "Kilometres"
distance = StartPoint.DistanceFromInMetres(CurrentPosition) / 1000D
End Select
Me.FlownBox.Text = distance.ToString("N2")
[/CODE]

But, the result is my current postion to 0 postion. Because don´t read

[CODE]Latitude.Value[/CODE]

at the StartLatitude and

[CODE]Longitude.Value[/CODE]

at the StartLogintude. But, I replace that for the cordinates like EGLL in the VB EXAMPLE. Works but it shows me the distance to heatrow and not the distance flown, logical.

Link to comment
Share on other sites

Public Class MainForm

'Some Code
Dim StartPoint As FsLatLonPoint

' Initialise some of the variables we will need later
Public Sub New()
	 InitializeComponent()
	 Dim StartLat As FsLatitude = New FsLatitude(Latitude.Value)
	 Dim StartLon As FsLongitude = New FsLongitude(Longitude.Value)
	 StartPoint = New FsLatLonPoint(StartLat, StartLon)
End Sub
[/CODE]

But, the result is my current postion to 0 postion. Because don´t read [CODE]Latitude.Value[/CODE]
 at the StartLatitude and [CODE]Longitude.Value[/CODE]
 at the StartLogintude.

You should move this code from the constructor (new()).  It's too early here.  The FSUIPC connection isn't even open.  You should put this code after the connection is opened.  Something like this:
[code]
	 FSCUIPCConnection.Open()
	 ' Initialise start position
	 FSUIPCConnection.Process()
	 Dim StartLat As FsLatitude = New FsLatitude(Latitude.Value)
	 Dim StartLon As FsLongitude = New FsLongitude(Longitude.Value)
	 StartPoint = New FsLatLonPoint(StartLat, StartLon)

Of course this means the start position is fixed to whereever the user was when they started your application. It would probably make sense to put a way of resettting the start position in your application (like a button) and calling a method:

Public Sub SetStartPosition()
	 ' set start position
	 FSUIPCConnection.Process()
	 Dim StartLat As FsLatitude = New FsLatitude(Latitude.Value)
	 Dim StartLon As FsLongitude = New FsLongitude(Longitude.Value)
	 StartPoint = New FsLatLonPoint(StartLat, StartLon)
End Sub

Paul

Link to comment
Share on other sites

I have another problem now. I only get the position at the start and the current position. But, I take-off and I return to the same airport. I have a problem because the position at the start and the current are near and it only shows me that I flown, for example, only 0.23NM but It´s false.

I think I can fix this problem resetting the position in the timer1, and plus it than the value of the FlownTextBox. I test a lot of forms to this but doesn´t work.

Paul, Do you have an idea to do this?

Link to comment
Share on other sites

I have another problem now. I only get the position at the start and the current position. But, I take-off and I return to the same airport. I have a problem because the position at the start and the current are near and it only shows me that I flown, for example, only 0.23NM but It´s false.

You need to take positions at regular intervals (say once a minute for an airliner, probably more often for a small GA aircraft), and compute the small distances, adding them to a total as you go. Obviously not all flights are just one straight line!

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.