Page 1 of 1

Getting User Position

Posted: Thu Oct 17, 2019 11:15 am
by Kaiii3
Hey,

after upgrading V4 as well as the SDK to HF2 I have a problem in my software when trying to get the current User Position, the code was running in HF1:

Code: Select all

this.SimConnect.AddToDataDefinition(DataIdentifier.RecieveUserPositionQuery, "PLANE LATITUDE", // Simulation Variable "degrees", // Units - for strings put 'null' SIMCONNECT_DATATYPE.FLOAT64, // Data type 0.0f, SimConnect.SIMCONNECT_UNUSED); this.SimConnect.AddToDataDefinition(DataIdentifier.RecieveUserPositionQuery, "PLANE LONGITUDE", // Simulation Variable "degrees", // Units - for strings put 'null' SIMCONNECT_DATATYPE.FLOAT64, // Data type 0.0f, SimConnect.SIMCONNECT_UNUSED); this.SimConnect.AddToDataDefinition(DataIdentifier.RecieveUserPositionQuery, "PLANE ALTITUDE", // Simulation Variable "Feet", // Units - for strings put 'null' SIMCONNECT_DATATYPE.FLOAT64, // Data type 0.0f, SimConnect.SIMCONNECT_UNUSED);
Struct is looking like this:

Code: Select all

public struct Position { public double latitude; public double longitude; public double altitude; }
problem is now that the structure has not the correct values. For example my current Position in the Sim is:

Lon -122, Lat 47, Alt 24

the return struct has: Lon 47, Lat 0, Alt -122


i have used the codeparts above for collecting AI Traffic as well, using the SIMCONNECT_SIMOBJECT_TYPE.AIRCRAFT I get the correct values for the user aircraft, any ideas?

Re: Getting User Position

Posted: Thu Oct 17, 2019 12:29 pm
by Kaiii3
to clarify a bit more:

by using this i get the wrong values:

Code: Select all

this.SimConnect.RequestDataOnSimObjectType(DataIdentifier.RecieveUserPositionQuery, DataIdentifier.RecieveUserPositionQuery, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
using this i get the correct values:

Code: Select all

this.SimConnect.RequestDataOnSimObjectType(DataIdentifier.RecieveAIObjectQuery, DataIdentifier.RecieveAIObjectQuery, 0,SIMCONNECT_SIMOBJECT_TYPE.AIRCRAFT);
Seems that SIMCONNECT_SIMOBJECT_TYPE is making the difference here

Re: Getting User Position

Posted: Thu Oct 17, 2019 1:37 pm
by Kaiii3
ok I did some more tests and was able to "fix" the problem on my end by changing the order of var's in my struc.

According to the SDK the order of calling AddToDataDefinition must be the same as the struct. As you can see in my first post I did that in my Code.

Now while a bit try and error I have changed the order of my struct and endeb up with this code that is working:

Code: Select all

public struct Position { /* NOT WORKING public double Latitude; public double Longitude; public double Altitude; */ public double Altitude; public double Latitude; public double Longitude; }
No clue why this fixed the problem...