示例#1
0
            public static GPS FromDegreesSecondsMinutes(string location)
            {
                var r = new Regex(
                    @"^([0-9]+. [0-9]+. [0-9]+. \w( )*)+$");
                var r2 = new Regex(
                    @"^([0-9]+.[0-9]+.[0-9]+. \w( )*)+$");

                if (r2.IsMatch(location))
                {
                    string[] parts = location.Split(' ');
                    if (!parts.Length.Equals(8))
                    {
                        throw new SystemException("Invalid format of GPS coordinates.");
                    }

                    decimal longitude = GPS.DegreesMinutesSecondsToDegrees(
                        decimal.Parse(parts[0]),
                        decimal.Parse(parts[1]),
                        decimal.Parse(parts[2])
                        );

                    decimal latitude = GPS.DegreesMinutesSecondsToDegrees(
                        decimal.Parse(parts[4]),
                        decimal.Parse(parts[5]),
                        decimal.Parse(parts[6])
                        );

                    if (parts[3].Equals('W'))
                    {
                        longitude *= -1;
                    }
                    if (parts[7].Equals('S'))
                    {
                        latitude *= -1;
                    }

                    return(new GPS(longitude, latitude));
                }
                else
                {
                    throw new SystemException("Invalid format of GPS coordinates.");
                }
            }