Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Parsing Latitude and Longitude Information

, 21 Feb 2012
Parses user input and extracts latitude and longitude information, taking into account the user's language and regional settings
using System.IO;
using System.Xml.Serialization;
using Geospatial;
using NUnit.Framework;

namespace UnitTests
{
    internal static class TestHelpers
    {
        private const double Delta = 0.000001;

        public static T Serialize<T>(T obj)
        {
            var serializer = new XmlSerializer(typeof(T));
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, obj);

                // Return a deserialized copy
                stream.Position = 0;
                return (T)serializer.Deserialize(stream);
            }
        }

        public static Location CreateLocation(double latitude, double longitude)
        {
            return new Location(Latitude.FromDegrees(latitude), Longitude.FromDegrees(longitude));
        }

        public static Location CreateLocation(double latitude, double longitude, double altitude)
        {
            return new Location(Latitude.FromDegrees(latitude), Longitude.FromDegrees(longitude), altitude);
        }

        public static void AssertLocationsAreEqual(Location locationA, Location locationB)
        {
            if ((locationA == null) || (locationB == null))
            {
                Assert.IsTrue(locationA == locationB);
            }
            else
            {
                Assert.AreEqual(locationA.Latitude.TotalDegrees, locationB.Latitude.TotalDegrees, Delta);
                Assert.AreEqual(locationA.Longitude.TotalDegrees, locationB.Longitude.TotalDegrees, Delta);

                if (locationA.Altitude != null)
                {
                    Assert.IsNotNull(locationB.Altitude);
                    Assert.AreEqual(locationA.Altitude.Value, locationB.Altitude.Value, Delta);
                }
                else
                {
                    Assert.IsNull(locationB.Altitude);
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Samuel Cragg

United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 21 Feb 2012
Article Copyright 2011 by Samuel Cragg
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid