Пример #1
0
        /// <summary>
        /// 转换纬度为度分秒
        /// </summary>
        /// <param name="latitude"></param>
        /// <returns></returns>
        private string FormatLatitudeToCelsiusMinuteSecondHanzi(double latitude)
        {
            var wd    = latitude;
            var tipWD = string.Empty;

            if (wd >= 0) //北纬N
            {
                tipWD = "N";
            }
            else
            {
                tipWD = "S"; //南纬S
                wd    = 0 - wd;
            }

            int    Celsius_WD, Minute_WD, Second_WD;
            string strCelsius_WD, strMinute_WD, strSecond_WD;

            Celsius_WD = (int)Math.Floor(wd);
            if (Celsius_WD < 10) //只有一位,补一个0
            {
                strCelsius_WD = "0" + Celsius_WD;
            }
            else
            {
                strCelsius_WD = Celsius_WD.ToString();
            }
            strCelsius_WD += "度";

            Minute_WD = (int)Math.Floor((wd - Celsius_WD) * 60);
            if (Minute_WD < 10) //只有一位,补一个0
            {
                strMinute_WD = "0" + Minute_WD;
            }
            else
            {
                strMinute_WD = Minute_WD.ToString();
            }
            strMinute_WD += "分";
            Second_WD     = (int)Math.Floor((Convert.ToDecimal((wd - Celsius_WD) * 60) - Minute_WD) * 60);
            if (Second_WD < 10)
            {
                strSecond_WD = "0" + Second_WD;
            }
            else
            {
                strSecond_WD = Second_WD.ToString();
            }
            strSecond_WD += "秒";
            var strDMSWD = string.Format("{0}{1}{2}{3}", strCelsius_WD, strMinute_WD, strSecond_WD, tipWD);

            return(strDMSWD);
        }
Пример #2
0
        /// <summary>
        ///     转换纬度为度分格式
        /// </summary>
        /// <param name="latitude"></param>
        /// <returns></returns>
        public string FormatLatitudeToCelsiusMinuteHanzi(double latitude)
        {
            var wd    = latitude;
            var tipWD = string.Empty;

            if (wd >= 0) //北纬N
            {
                tipWD = "N";
            }
            else
            {
                tipWD = "S"; //南纬S
                wd    = 0 - wd;
            }

            int    Celsius_WD, Minute_WD;
            string strCelsius_WD, strMinute_WD;

            Celsius_WD = (int)Math.Floor(wd);
            if (Celsius_WD < 10) //只有一位,补一个0
            {
                strCelsius_WD = "0" + Celsius_WD;
            }
            else
            {
                strCelsius_WD = Celsius_WD.ToString();
            }
            strCelsius_WD += "度";

            Minute_WD = (int)Math.Floor((wd - Celsius_WD) * 60);
            if (Minute_WD < 10) //只有一位,补一个0
            {
                strMinute_WD = "0" + Minute_WD;
            }
            else
            {
                strMinute_WD = Minute_WD.ToString();
            }
            strMinute_WD += "分";


            var strDMSWD = string.Format("{0}{1}{2}", strCelsius_WD, strMinute_WD, tipWD);

            return(strDMSWD);
        }
Пример #3
0
        /// <summary>
        ///     转换纬度为°格式
        /// </summary>
        /// <param name="latitude"></param>
        /// <returns></returns>
        public string FormatLatitudeToCelsius(double latitude)
        {
            var wd    = latitude;
            var tipWD = string.Empty;

            if (wd >= 0) //北纬N
            {
                tipWD = "N";
            }
            else
            {
                tipWD = "S"; //南纬S
                wd    = 0 - wd;
            }
            int    Celsius_WD, Minute_WD;
            string strCelsius_WD, strMinute_WD;
            var    strDMSWD = "";

            Celsius_WD = (int)Math.Floor(wd);
            if (Celsius_WD < 10) //只有一位,补一个0
            {
                strCelsius_WD = "0" + Celsius_WD;
            }
            else
            {
                strCelsius_WD = Celsius_WD.ToString();
            }
            if ((wd - Celsius_WD) == 0)
            {
                strCelsius_WD += "°";
                strDMSWD       = string.Format("{0}{1}", strCelsius_WD, tipWD);
            }
            else
            {
                Minute_WD = (int)Math.Floor((wd - Celsius_WD) * 60);
                if (Minute_WD < 10) //只有一位,补一个0
                {
                    strMinute_WD = "0" + Minute_WD;
                    strDMSWD     = string.Format("{0}{1}{2}", strCelsius_WD + ".", strMinute_WD + "°", tipWD);
                }
                else
                {
                    if (Minute_WD >= 60)
                    {
                        Celsius_WD++;
                        if (Celsius_WD < 10) //只有一位,补一个0
                        {
                            strCelsius_WD = "0" + Celsius_WD;
                        }
                        else
                        {
                            strCelsius_WD = Celsius_WD.ToString();
                        }

                        strDMSWD = string.Format("{0}{1}{2}", strCelsius_WD + ".", (Minute_WD - 60) + "°", tipWD);
                    }
                    else
                    {
                        strMinute_WD = Minute_WD.ToString();
                        strDMSWD     = string.Format("{0}{1}{2}", strCelsius_WD + ".", strMinute_WD + "°", tipWD);
                    }
                }
            }

            return(strDMSWD);
        }