Jump to content
The simFlight Network Forums

Recommended Posts

Posted

HI there,

I am trying to read the latitude and longitude from FSX. I have gotten the raw, unformatted data from FSX, but I am having trouble converting it to a usable format.

I have converted the unsigned long long to a float while applying the conversions, but I am either getting inaccurate data (i.e. 42.7445 when it should be 42.4542) or I get just even 42.

Here is my code: (There is a call to FSUIPC_Process in there, I just haven't actually included it in the example).


signed long long LAT;

FSUIPC_Read(0x0560,8,&LAT,&result);

float y = LAT;

y *= 90;

y /= 10001750;
y /= 65536;
y /= 65536;

p->latitude = y; //p is a user defined an aircraft data struct[/CODE]

Thanks in advance,

--

Collin Biedenkapp

Posted

In vb.net I use 'long' variable type then copy it into a 'single'.

'code below is snippets from various parts of a class module in vb.net'


Private fsLatitude As Offset(Of Long) = New FSUIPC.Offset(Of Long)("position", &H560)
Public CurrentLatitude As Single

FSUIPCConnection.Process("position")

Me.CurrentLatitude = Me.fsLatitude.Value
Me.CurrentLatitude = Me.CurrentLatitude* 90D / (10001750D * 65536D * 65536D)
[/CODE]

What language are you using? Why 'long long' and not simply 'long?'.

Posted

I use long long because I need a 64 bit integer, where as long is 32, int is 16, etc. It's a whole mess in C++ that isn't needed in .Net.

I got a decimal at least, but it's still wrong (using a method similar to yours). I'll have to review it in the morning.

Posted

You are losing precision by copying to a float. Use a double.


long long Lat;
double dLat;

if (FSConnection.ReadAndProcess(0x568, 8, &Lat)
{
dLat = Lat;
dLat = dLat*90.0/(10001750.0 * 65536.0 * 65536.0);
}
...
...
[/CODE]

Posted

I did the above conversion, I got 42.741640579659617 when the in-sim latitude read N42*44.50'

Is that normal?

By "normal" do you mean "correct"? If so, of course it is correct.

42.7416406 (the nearest I can get in my calculator) = 42*44.498436 which would certainly be 42*44.50' to the nearest 1/100th of a minute! What is your problem? Check it yourself on a calculator (just multiply the fractional degrees by 60 to get minutes of course)!

Pete

Posted

'just multiply the fractional degrees by 60 to get minutes of course' - that seems to have been my problem. It slipped my mind that we are dealing with fractions of 60, not of 100, therefore, I was reading it as 42* 74'15, without multiplying to get minutes and seconds.

Thank you for the help everyone, as it is working now. This should hopefully have been my last stupid question.

--

Collin

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.