Resumé

Convert Between Degrees and Decimals using .Net

Cristian Merighi () 5.00

This article is about the development of a struct (C#) of mine which permits an agile conversion between values formatted as Degrees Minutes Second and values formatted as Decimals. It can be useful in a scenario where Virtual Earth or Google maps are involved, in order to set the correct latitude and longitude.
This article is obsolete. Some functionalities might not work anymore. Comments are disabled.

Nowadays a customer who requests a "contect us" section for his website should be served with a mapping/routing service like those provided by Google or Microsoft (very nice packed ones).

The parameters passed in order to visualize the right portion of the world are the usual Latitude and Longitude. One of the common problems you could face is the conversion between standard/scientific/conventional degrees format for latitude and longitude (deg° mins' secs") and the latitude and longitude format accepted by this kind of web controls (int.float).

My structuring mania pushed me to write a personal Struct to handle this type of values: here's the related diagram...

Demo

Example about the use (VB.Net code)

Dim deg As Pacem.Math.Deg = Pacem.Math.Deg.FromDouble(10.234)
Dim deg2 As Pacem.Math.Deg = Pacem.Math.Deg.FromDegValues(10, 14, 2.4)
Dim toparse As String = "10° 34' 55.23"""

' Flushing to the Page
Response.Write(deg.ToString() & _
" -- " & _
deg2.ToDouble().ToString() & _
" -- " & _
Pacem.Math.Deg.Parse(toparse, System.Globalization.CultureInfo.InvariantCulture).ToString())

Test it!

zip file « download Pacem.Math.Deg struct

Take care. Bye.

Feedbacks

  • Re: Convert Between Degrees and Decimals using .Net

    Antonello Saturday, January 31, 2009 5.00

    ottimo mi serviva proprio. la mia calcolatrice a dato forfait

  • Re: Convert Between Degrees and Decimals using .Net

    roby Saturday, April 04, 2009 5.00

    Ottimo, mi servirà per utilizzare al meglio il mio GPS. Grazie e saluti.

feedback
 

Syndicate

Author

Cristian Merighi facebook twitter google+ youtube

Latest articles

Top rated

Archive

Where am I?

Author

Cristian Merighi facebook twitter google+ youtube

I'm now reading

Feeds