The simFlight Network Forums

# Offset for flown distance

## Recommended Posts

Hi,

As the name says, is there an offset the monitor your distance flown, because I can't find them in the manual.

##### Share on other sites

Hi Erik,

There isn't one.  You're program needs to track this during the flight.  At regular intervals you need to calculate the distance between the current position and the previous position and add this to a total distance variable.

The DLL can handle the trigonometry for you if you use the FsLatLonPoint class.  This takes in an FsLongitude and FsLatitude to specify a position on the Earth.  You can use one of the DistanceFrom...() methods to calculate the distance between two positions.

The FsLongitude and FsLatitude classes take in the raw 8-byte value from the fsuipc offset so you don't need to worry about converting this to degrees.

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

##### Share on other sites

Hi,

Mm okay thank you. I took a look at the manual and the distance between you and EGLL. That's works for me. But what I want is the position from that you start FS. So in the DIM where you write down the coordinates from egll. It should be the coordinates of your starting location. But I have no idea how to get that.

##### Share on other sites

Hi Erik,

There are no offsets to tell you the starting location.  In any case the distance between the starting point and the current aircraft location isn't really going to be the distance flown because not many routes are in a straight line.

You'll need to have a button in your application which the the user presses when they are at the starting location. When this button is pressed you read the current position of the aircraft and store it in a variable as the 'previous location'.

Then at regular intervals you get the current position again, work out the distance from the 'previous location' and add it to the total distance flown.  Then you copy the current location into the 'previous location' ready for the next time.

The more frequently you sample the position the more accurate your total distance will be, and the more frequently you can update your display of the distance so far.  I would suggest once every 30 seconds would be good enough but you could make it more or less frequent according to your preferences.  You should add another timer to your form to do this calculation at your chosen interval.

Paul

##### Share on other sites

Erik,

Don't know what language you are programming in but here is what I wrote for my app in vb.net.

You can modify this into whatever language you are using. The maths is there but you will need to change the objects/vars to match your app

```    Sub GetTotalDistanceFlown()

'calculate total distance flown so far'
Static firstrun As Boolean = True

If firstrun = True Then
'remember position for next run otherwise distance starts with lat/lon of 0 and gives 6000nm at KSEA!'
PreviousLat = ApplicationObjects.objAircraft.CurrentLatitude
PreviousLon = ApplicationObjects.objAircraft.CurrentLongitude
firstrun = False
Else

'as total distance is in nm convert to rad before calculating new distance'
ReportGlobal.TotalDistanceFlownNM = ReportGlobal.TotalDistanceFlownNM + (2 * Math.Asin(Math.Sqrt((Math.Sin((PreviousLat - CurrentLat) / 2)) ^ 2 + Math.Cos(PreviousLat) * Math.Cos(CurrentLat) * (Math.Sin((PreviousLon - CurrentLon) / 2) ^ 2))))
ReportGlobal.TotalDistanceFlownNM = Math.Round(ReportGlobal.TotalDistanceFlownNM, 4)
'4 decimal places for accuracy on chart x axis'

PreviousLat = ApplicationObjects.objAircraft.CurrentLatitude
PreviousLon = ApplicationObjects.objAircraft.CurrentLongitude
End If

End Sub

```

required function for above

```    Shared Function Rad2nm(ByVal Rad)
'This function converts radians to nm'
End Function

'This function converts radians to nm'
nm2Rad = nm * Math.PI / (180 * 60)
End Function
```
##### Share on other sites

Oke, thank you both for your help. I am making it in VB.net.  BUt what do you mean with ApplicationObjects?  And for Previous lat and lon I have add this

Dim PreviousLat As FsLatitude = New FsLatitude(Latitude.Value)

Dim PreviousLon As FsLongitude = New FsLongitude(Longitude.Value)

And should I make another dim.... for the CurrentLat and lon with the same value of lat and lon?

## Create an account

Register a new account

×

• #### Activity

×
• Create New...