Convert decimal coordinates to Degrees, Minutes & Seconds by c#

后端 未结 4 665
说谎
说谎 2021-01-07 11:12

Has anyone know simple short code to convert this without use additional libraries ?

4条回答
  •  無奈伤痛
    2021-01-07 12:05

    I came up with the following. It correctly handles negative coordinates (south latitude or west longitude) and returns the remainder (in degrees) that was not evely divided into minutes or seconds.

    public static double ConvertDecimalToDegMinSec(double value, out int deg, out int min, out int sec)
    {
        deg = (int)value;
        value = Math.Abs(value - deg);
        min = (int)(value * 60);
        value = value - (double)min / 60;
        sec = (int)(value * 3600);
        value = value - (double)sec / 3600;
        return value;
    }
    

提交回复
热议问题