Jump to content
The simFlight Network Forums

Converting FS units to Decimal Lat/long

Recommended Posts

This stuff's all in the SDK Patrik. If you look there first you'll save yourself the time of aiting for a reply.

Latitude of aircraft in FS units.

To convert to Degrees:

If your compiler supports long long (64-bit) integers then use such a variable to simply copy this 64-bit value into a double floating point variable and multiply by 90.0/(10001750.0 * 65536.0 * 65536.0).

Otherwise you will have to handle the high 32-bits and the low 32-bits separately, combining them into one double floating point value (say dHi). To do, copy the high part (the 32-bit int at 0564) to one double and the low part (the 32-bit unsigned int at 0560) to another (say dLo). Remember that the low part is only part of a bigger number, so doesn’t have a sign of its own. Divide dLo by (65536.0 * 65536.0) to give it its proper magnitude compared to the high part, then either add it to or subtract it from dHi according to whether dHi is positive or negative. This preserves the integrity of the original positive or negative number. Finally multiply the result by 90.0/10001750.0 to get degrees.

Either way, a negative result is South, positive North.


Link to comment
Share on other sites

This is what I use....

If FSUIPC_Read(&H560, 8, VarPtr(Fake64Bit), dwResult) Then

If FSUIPC_Process(dwResult) Then

StartLat = Fake64Bit * 10000#

StartLat = StartLat * 90# / (10001750# * 65536# * 65536#)

modVars.StartLatitude = StartLat

End If

End If

It does return a decimal like -122.23456 or something.

Fake64Bit is a Currency Declaration. It fakes VB out to grab floating 64 bit info.

If you dont force the doubles (#) you will constantly get overflow errors.


Link to comment
Share on other sites

I got the latitude to work, however, I can't seem to get a decent value for the Longitude... I get a value at 12345,000000 something instead of -124,4323 which is the correct one. I just modified the code from Lat...

If FSUIPC_Read(&H568, 8, VarPtr(Fake64Bit), dwResult) Then

If FSUIPC_Process(dwResult) Then

CurLong = Fake64Bit * 10000#

CurLong = CurLong * 90# / (10001750# * 65536# * 65536#)

End If

End If

Any Ideas?

Link to comment
Share on other sites

Forget it, I had a look in the SDK and saw that I was formatting the data erroneously, it should be 65536# * 65536# * 65536# * 65536# instead of 10001750# * 65536# * 65536#. Also, it should be divided by 360 and not 90.

Regards and a lot of thanks for the help!


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.