Jump to content
The simFlight Network Forums

FSUIPC More Accurate Latitude and Longitude


Recommended Posts

Hello,

Is it possible to get more accurate latitude and longitude data from FSX than 3-4 decimal places after conversion into decimal degrees?

Currently I am fetching the data using a long long variable type, then converting it into a double before carrying out the conversion. Am I doing something wrong here with my variable types?

The result of this is a three decimal place number for longitude and a four decimal place number for latitude (both numbers have a total of 6 digits each). Would I get more accurate results if I used SimConnect instead of FSUIPC?

I am using C++ to do this. Thank you for any help in advance.

Link to comment
Share on other sites

Hello,

Is it possible to get more accurate latitude and longitude data from FSX than 3-4 decimal places after conversion into decimal degrees?

Currently I am fetching the data using a long long variable type, then converting it into a double before carrying out the conversion. Am I doing something wrong here with my variable types?

The result of this is a three decimal place number for longitude and a four decimal place number for latitude (both numbers have a total of 6 digits each). Would I get more accurate results if I used SimConnect instead of FSUIPC?

I am using C++ to do this. Thank you for any help in advance.

 

How are you managing to only get 4 decimal places in degrees? Both latitude and longitude are very accurate. The values at offsets 0560 and 0568 are 64-bit precision stored in such a way that the maximum precision is preserved -- theoretically more than the precision offered by the 64-bit floating point form where some of the bits are reserved for the exponent. Of course, in FSX (unlike in FS9 and before), those offsets are computed from the 64-bit floating point values supplied by SimConnect, so just retain exactly the same precision.

 

It sounds like you have some limitation in your code or in the way you are displaying it?

 

There is also a GPS latitude and longitude in 64-bit floating point at offsets 6010 and 6018, but I don't think those are updated every frame like the 0560/0568 ones.

 

Pete

Link to comment
Share on other sites

How are you managing to only get 4 decimal places in degrees? Both latitude and longitude are very accurate. The values at offsets 0560 and 0568 are 64-bit precision stored in such a way that the maximum precision is preserved -- theoretically more than the precision offered by the 64-bit floating point form where some of the bits are reserved for the exponent. Of course, in FSX (unlike in FS9 and before), those offsets are computed from the 64-bit floating point values supplied by SimConnect, so just retain exactly the same precision.

 

It sounds like you have some limitation in your code or in the way you are displaying it?

 

There is also a GPS latitude and longitude in 64-bit floating point at offsets 6010 and 6018, but I don't think those are updated every frame like the 0560/0568 ones.

 

Pete

Thank you for your quick reply!

 

An example of the data I am getting is this:

 

Latitude: -31.9707

Longitude: 115.868

 

This code responsible for fetching the latitude and longitude is this:

long long chLat;
double chdlat;
long long chLong;
double chdLong;

if (FSConnection.ReadAndProcess(0x560, 8, &chLat))
{
chdlat=chLat;
chdlat=chdlat*90.0/(10001750.0 * 65536.0 * 65536.0);
std::ofstream lat_file(
"ILat.txt", std::ios_base::out | std::ios_base::trunc);
lat_file << chdlat;
lat_file << "\n";
}
 
if (FSConnection.ReadAndProcess(0x568, 8, &chLong))
{
chdLong=chLong;
chdLong=chdLong*360.0/(65536.0 * 65536.0 * 65536.0 * 65536.0);
std::ofstream long_file(
"ILong.txt", std::ios_base::out | std::ios_base::trunc);
long_file << chdLong;
long_file << "\n";
}
Edited by sam.white
Link to comment
Share on other sites

This code responsible for fetching the latitude and longitude is this:

...

 

What does << do there? I assume that's some sort of C++ output method? (I use C and ASM, not C++).

 

What is the actual value of  the doubles before you output them? Check with a debugger, or do your own formatting. You probably have whatever << does set to format things to  6 decimal places.

 

Also, it's easy enough to test even without a debugger -- multply the value by 100 before sending it to << and see if there are still 6 decimal places! ;-)

 

Pete

Link to comment
Share on other sites

What does << do there? I assume that's some sort of C++ output method? (I use C and ASM, not C++).

 

What is the actual value of  the doubles before you output them? Check with a debugger, or do your own formatting. You probably have whatever << does set to format things to  6 decimal places.

 

Also, it's easy enough to test even without a debugger -- multply the value by 100 before sending it to << and see if there are still 6 decimal places! ;-)

 

Pete

 

After a little googling I find that the C++ default precision for cout is 6 decimal places. If you want to change that there's a function:

std::setprecision

C++ is new to you? (It is to me, that's why I need to look things up! ;-) ).

 

Regards

Pete

Link to comment
Share on other sites

After a little googling I find that the C++ default precision for cout is 6 decimal places. If you want to change that there's a function:

std::setprecision

C++ is new to you? (It is to me, that's why I need to look things up! ;-) ).

 

Regards

Pete

Thank you so much! :D

 

I never thought to check precision values! C++ is very new to me, I have only been programming with it for around two weeks or so, and before that I was mostly doing PHP and web based programming.

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.