The simFlight Network Forums

# Converting FS units to Decimal Lat/long

## Recommended Posts

Well, the topic says it all :) I want to take the units provided by FS and convert them into decimal Latitude and Longitude. I'm working in VB6, so if anyone has an idea, please share.

Patrik

##### Share on other sites

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.

Richard

##### Share on other sites

I saw that, however I was uncertain wether it would provide me with decimal values or not.

Regards,

Patrik

##### 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.

Mike

##### 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?

##### 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!

Patrik

## Create an account

Register a new account