Converting decimal numbers to latitude and longitude

I have a GPS device that sends data to my server, I need to convert the decimal values ​​that the device sends to latitude and longitude. I am not good at math, so all my attempts have failed, here are the specifications:

Latitude

Occupy 4 bytes representing the value of latitude.

The range of numbers is from 0 to 162000000, which represents a range from 0 Β° to 90 Β°. Unit: 1/500 second Conversion Method:

A) Converting latitude data (degrees, minutes) from the GPS module into a new form, which represents the value in minutes only;

B Multiply the converted value by 30000, and then convert the result to a hexadecimal number

For example, 22 Β° 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 the location data. The number ranges from 0 to 324000000, representing a range from 0 Β° to 180 Β° .Unit: 1/500 seconds, the conversion method matches the latitudes.

I came up with this function, but it does not 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; 
+4
source share
1 answer

numar indicated in 1/500 of a second. So, the following relations are true:

 num/500 = seconds num/500/60 = minutes num/500/60/60 = degrees 

I would calculate it all like this:

 var degrees, minutes, seconds: Integer; .... degrees := num div (500*60*60); minutes := num div (500*60) - degrees*60; seconds := num div 500 - minutes*60 - degrees*60*60; 

If you need to calculate the fractional part of seconds, do it like this. Please note that here simply does not need Extended .

 var degrees, minutes: Integer; seconds: Double; .... degrees := num div (500*60*60); minutes := num div (500*60) - degrees*60; seconds := num/500 - minutes*60 - degrees*60*60; 

Connect your 40582974 value to this formula and the results:

 degrees: 22 minutes: 32 seconds: 45 

Judging by the comments, what you really want is degrees as an integer and minutes as a floating point. This can be done like this:

 var degrees: Integer; minutes: Double; .... degrees := num div (500*60*60); minutes := num/(500*60) - degrees*60; 

Connect your 40582974 value to this formula and the results:

 degrees: 22 minutes: 32.7658 
+13
source

Source: https://habr.com/ru/post/1413925/


All Articles