Degrees Minutes Seconds to Decimal Degrees

Does any one by chance have a routine to convert Degrees Minutes Seconds to Decimal Degrees and back.

I am trying to convert GPS to Latitude/Longitude (Degrees Minutes Seconds to Decimal Degrees)
and from Latitude/longitude to GPS (Decimal Degrees to Degrees Minutes Seconds)

Example Outputs
GPS would be something like N43" 43. 567 and W095"42.678

LatitudeN 45.1556168
Longitude -85.1413060

This is an image view of what I am trying to do.

Pretty sure it’s just something like this:

  dim mult as double = 1.
  if degrees < 0. then mult = -1.
  dim part as double = seconds / 60.
  part = ( minutes + part ) / 60.

  dim coord as double = abs( degrees ) + part
  coord = coord * mult

Below is what I found about it but I did not get the expecetd values from the information.

[quote]Conversion from DMS to Decimal Degree

Given a DMS (Degrees, Minutes, Seconds) coordinate such as W079°58?56?, convert it to a number of decimal degrees using the following method:

Calculate the total number of seconds:
58?56? = (58*60 + 56) = 3536 seconds.
The fractional part is the total number of seconds divided by 3600:
3536 / 3600 = ~0.982222
Add fractional degrees to whole degrees to produce the final result:
79 + 0.982222 = 79.982222
Since it is a West longitude coordinate, negate the result.
The final result is -79.982222.

Conversion from MinDec to Decimal Degree

Given a MinDec (Degrees, Minutes, Decimal Minutes) coordinate such as 79°58.93172W, convert it to a number of decimal degrees using the following method:

The integer number of degrees is the same (79)
The decimal degrees is the decimal minutes divided by 60 (58.93172/60 = ~0.982195)
Add the two together (79 + 0.982195= 79.982195)
For coordinates ind the western (or southern) hemisphere, negate the result.
The final result is -79.982195

Conversion from Decimal Degree to DMS

Given a decimal longitudinal coordinate such as -79.982195 it will be necessary to know whether it is a latitudinal or longitudinal coordinate in order to fully convert it. The method is as follows:

Subtract the whole number portion of the coordinate, leaving the fractional part. The whole number is the number of degrees. In the example of -79.982195: -79 degrees.
Multiply the remaining fractional part by 60. This will produce a number of minutes in the whole number portion. In the example: 0.982195 x 60 = 58.9317 => 58 minutes.
Multiply the fractional part of the number of minutes by 60, producing a number of seconds. 0.9317 x 60 = 55.903 => 55.903 seconds. It is possible to keep the entire number, truncate to the decimal 55 or round to the decimal 56.
Depending on whether the source number was a latitudinal or longitudinal coordinate, and the sign of the number, add the N/S/E/W specifier. The following table shows the possibilities:

Type Dir. Sign Test
Lat. N + > 0
Lat. S - < 0
Long. E + > 0
Long. W - < 0

A latitude of 0°0?0? (at The Equator) is neither North nor South. Similarly, a longitude of 0°0?0? (at the Prime Meridian) is neither East nor West. These are referred to as zero latitude and zero longitude, respectively. A longitude of 180°0?0? (the 180th meridian) is neither East nor West. This is the basis for the International Date Line when referring to the Earth.

The final result for the above example is: W 79°58?56?.

Programmatical conversion (not sure what language this is)

The most common programmatical use of these processes is to display a coordinate to an end user in the more common DMS form instead of decimal form. Below is a piece of pseudocode to convert from decimal degrees to degrees, minutes, and seconds:

function deg_to_dms ( degfloat )
Input must be non-negative:
if degfloat < 0
end if
Compute degrees, minutes and seconds:
deg ? integerpart ( degfloat )
minfloat ? 60 * ( degfloat - deg )
min ? integerpart ( minfloat )
secfloat ? 60 * ( minfloat - min )
Round seconds to desired accuracy:
secfloat ? round( secfloat, digits )
After rounding, the seconds might become 60. These two
if-tests are not necessary if no rounding is done.
if secfloat = 60
min ? min + 1
secfloat ? 0
end if
if min = 60
deg ? deg + 1
min ? 0
end if
Return output:
return ( deg, min, secfloat )
end function


function DMStoDegrees(d as double, m as double, s as double) as double
return sign(d)*(abs(d) + abs(m)/60.0 + abs(s)/3600.0)
end function

sub DegreesToDMS(deg as double, byref d as double, byref m as double, byref s as double)
dim v as double = abs(deg)
d = floor(v)*sign(deg)
v = (v-floor(v))*60.0
m = floor(v)
s = (v-m)*60.0
end sub

Hello Paul
I have the first method working great but I’m having a problem passing the
Latitude 45.1556168 Value or the Longitude -85.141306 Value to this method.

I should receive a GPS value something like 0123’42.543
I am trying to place the GPS values in their respective fields on the left side of the window.

Here is an image of what I’ve made so far. If anyone wants this when I’m done I will post the file.

Well, I just tried this (with the exact code I gave):

dim d,m,s as double DegreesToDMS(-85.141306,d,m,s) msgbox "-85.141306 = "+str(d)+":"+str(m)+":"+str(s)

and the following was displayed:

-85.141306 = -85:8:28.7016

Thanks Paul

That did the trick. I was not passing the variables correctly.