I have a GPS device which sends data to my server, I need to convert the decimal values that the device sends into latitude and longitude. I am bad at math so all my attempts failed, here are the specs:
Latitude
Occupy 4 bytes, representing the latitude value.
Number range is from 0 to 162000000, which represents the range form 0°to 90°.
Unit: 1/500 second Conversion method:
A) Convert the latitude (degrees, minutes) data from GPS module into a new form which represents the value only in minutes;
B Multiply the converted value by 30000, and then transform the result to hexadecimal number
For example22°32.7658′,(22×60+32.7658)×30000=40582974, then convert it to hexadecimal number 0x02 0x6B 0x3F 0x3E
Longitude
Occupy 4 bytes, representing the longitude value of location data. Number ranges from 0 to 324000000, representing the range form 0°to 180°.Unit: 1/500 seconds, Conversion method is the same as latitude’s.
I came up with this function but it doesn’t seem to work:
procedure GetDegree(const numar : DWORD; out min,sec : Extended);
var
eu : Extended;
begin
eu := numar / 30000;
min := Trunc(eu / 60);
sec := eu - min * 60;
end;
numaris specified in 1/500th of a second. So, the following equations hold:I would calculate it all like this:
If you need to calculate the fractional part of seconds then do it like this. Note that there’s simply no need for
Extendedhere.Plug your value of 40582974 into these formula and the results are:
Judging from comments what you actually want is degrees as an integer and minutes as a floating point. That you can do like this:
Plug your value of 40582974 into these formula and the results are: