HTCC-AB02S Displays incorrect Latitude / Longitude

My device says it finds and locks onto a GPS location but the latitude is off by over 40 miles. It appears as though it removes the zero’s in front after the decimal.
Example: latitude 41.0608 shows as 41.608
It does this even with the example Factory_Test_AB02S is loaded.
The longitude doesn’t display correct either. However the digits are correct. In the longitude it adds a minus sign after the decimal place but before the number.
Example: longitude -96.-7372
Any ideas what could be going on?
Here is the code that builds the lat/lon values - referenced from the Factory_Test_AB02S example
index = sprintf(str,“lat : %d.%d”,(int)Air530.location.lat(),fracPart(Air530.location.lat(),4));
index = sprintf(str,“lon:%d.%d”,(int)Air530.location.lng(),fracPart(Air530.location.lng(),4));

Partially solved.
In order to keep the leading zeros the code needs to be modified like this:
index = sprintf(str,“lat : %d.%04d”,(int)Air530.location.lat(),fracPart(Air530.location.lat(),4));
The %04 specifies to place leading zeros up to 4 places. So if it truncates any leading zeros it will put them back in.

Solved.
In order to get around the negative value. I created an if statement that checks if it is less than zero. If it is, multiply the value by -1.
The issue stems from the fracPart function that returns the negative value based off the lat/lon value in general.
I added the following within the scope.
int longitude;
int latitude;
longitude = fracPart(Air530.location.lng(),4);
if (longitude < 0)
{
longitude = longitude * -1;
}
latitude = fracPart(Air530.location.lat(),4);
if (latitude < 0)
{
latitude = latitude * -1;
}
and replaced the called fracPart function within the sprintf with the variable
int index = sprintf(str,“lat : %d.%04d \n”,(int)Air530.location.lat(),latitude);
index = sprintf(str,“lon: %d.%04d \n”,(int)Air530.location.lng(),longitude);

1 Like

Thank you! Works great!!