Jump to content
The simFlight Network Forums

unsigned long long for lat/long?


Recommended Posts

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

Link to comment
Share on other sites

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?'.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

'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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.