예제 #1
0
        /// <summary>
        /// 转换经纬度
        /// </summary>
        /// <returns></returns>
        public string ConvertLatLong()
        {
            if (string.IsNullOrEmpty(Lat) || string.IsNullOrEmpty(Long))
            {
                return("经纬度信息不全");
            }

            Regex regLat  = new Regex(@"\d{1,2}°\d{1,2}'\d{1,2}(.\d+)?""[NS]");
            Regex regLong = new Regex(@"\d{1,3}°\d{1,2}'\d{1,2}(.\d+)?""[EW]");

            if (regLat.IsMatch(Lat) && regLong.IsMatch(Long))
            {
                string newLat = string.Format("{0}{1}", Lat.Substring(Lat.Length - 1), Lat.Substring(0, Lat.Length - 1));
                newLat = newLat.Replace("°", string.Empty).Replace("'", string.Empty).Replace("\"", string.Empty);
                string newLong = string.Format("{0}{1}", Long.Substring(Long.Length - 1), Long.Substring(0, Long.Length - 1));
                newLong = newLong.Replace("°", string.Empty).Replace("'", string.Empty).Replace("\"", string.Empty);
                LatLong = newLat + newLong;
            }
            else
            {
                return("经纬度不满足格式");
            }
            return(string.Empty);
        }