MavLink Global position coordinates do not match with QGC widget

Per @LorenzMeier , opening a new issue here to continue discussion for the github issue at -

In short,
The code snippet in the above link requests the sUAS GPS Global Position coordinates.
The coordinates are returned but when the sUAS is flying, the MavLink inspector widget in QGC and the above code do not match in their latitude and longitude values. They are printed as ints so no decimal points and I print the value that is returned by the PX4 FC.

Looking for advice on if the code is missing something or is wrong.

Could you please share what is printed on the console and a screenshot of the MAVLink inspector?

Sure. I will run the test again today and paste it here.

That is a screenshot from the widget.

And here are the GPS coordinates my application pulls
latitude: 375611872:
longitude: -1223285103:
altitude: 41885:

Is it possible there is a slow connection between the PX4 and compute board from where I pull these coordinates ? The widget coordinates change in the 5th decimal. My application only changes in the 6th or 7th spot.

@LorenzMeier

Below is how I setup the connection with the PX4 FC

int px4_connection()
{

// TCP using localhost 
char *ip = (char *)"127.0.0.1";
int port = 5760; 
tcp_fd = socket(AF_INET, SOCK_STREAM, 0);

if (tcp_fd == -1) {
   printf("Could not create socket\n");
   return -1;
}  

bzero(&px4_sockaddr, sizeof(sockaddr));
px4_sockaddr.sin_family = AF_INET;
px4_sockaddr.sin_port = htons(port);
px4_sockaddr.sin_addr.s_addr = inet_addr(ip);
//sockaddr.sin_addr.s_addr = INADDR_ANY;

// Connect to the Intel Aero PX4 Flight controller 
if (connect(tcp_fd, (struct sockaddr *)&px4_sockaddr, sizeof(sockaddr)) == -1) {
    printf("Could not connect to socket: %d\n", errno);
    return -1;
}   
    
if (fcntl(tcp_fd, F_SETFL, O_NONBLOCK | O_ASYNC) < 0) {
    printf("Error setting socket as non-blocking \n");
    return -1;
}   
return 0;

I also did did this -

Hi @LorenzMeier
I think for now you can avoid looking into this. I think I notice that my application does get the latest and changing GPS coordinates and matches what the QGC widget shows. I do some processing on each GPS coordinate after receiving them in my application and that maybe is causing some delay. I will let you know how it goes.