Пример #1
0
        static void Main(string[] args)
        {
            Address moma = new Address();
            moma.Street = "West 53 Street";
            moma.Number = "11";
            moma.ZIP = "10019";
            moma.City = "New York";
            moma.State = "NY";
            moma.Country = "USA";

            TomTomClient gc = new TomTomClient("YOUR KEY");

            Console.WriteLine("Geocoding location of Moma NY: " + moma.ToString());
            var momaLocations = gc.CodeAddress(moma, 20);
            foreach (var momaPos in momaLocations)
            {
                Console.WriteLine(momaPos);
            }

            Console.WriteLine("Geocoding Central Park Zoo:");
            foreach(var pos in gc.CodeAddress("64 Fifth Avenue, New York, 10021", "USA", 20))
            {
                Console.WriteLine(pos);
            }

            Console.WriteLine("Press [any key]");
            Console.In.Read();
        }
Пример #2
0
        public List<Address> CodeAddress(Address address, int numberOfResult = 1)
        {
            List<string> parts = new List<string>();
            if (!string.IsNullOrEmpty(address.Number)) parts.Add(string.Format("ST={0}", (string)Uri.EscapeUriString(address.Number)));
            if (!string.IsNullOrEmpty(address.Street)) parts.Add(string.Format("T={0}", (string)Uri.EscapeUriString(address.Street)));
            if (!string.IsNullOrEmpty(address.City)) parts.Add(string.Format("L={0}", (string)Uri.EscapeUriString(address.City)));
            if (!string.IsNullOrEmpty(address.ZIP)) parts.Add(string.Format("PC={0}", (string)Uri.EscapeUriString(address.ZIP)));
            if (!string.IsNullOrEmpty(address.State)) parts.Add(string.Format("AA={0}", (string)Uri.EscapeUriString(address.State)));
            if (!string.IsNullOrEmpty(address.Country)) parts.Add(string.Format("CC={0}", (string)Uri.EscapeUriString(address.Country)));

            return CodeAddressInternal(string.Join("&", parts), numberOfResult);
        }
Пример #3
0
        private static Address ExtractReponseAddress(XPathNavigator nav)
        {
            Address address = new Address();

            // lat long
            NumberFormatInfo provider = new NumberFormatInfo() { NumberDecimalSeparator = ".", NumberGroupSeparator = "," };

            string lat = nav.SelectSingleNode(@"//*[local-name()='latitude']").Value;
            if (lat != null && lat.Length > 0)
            {
                address.Position.Latitude = Convert.ToDouble(lat, provider);
            }

            string lng = nav.SelectSingleNode(@"//*[local-name()='longitude']").Value;
            if (lng != null && lng.Length > 0)
            {
                address.Position.Longitude = Convert.ToDouble(lng, provider);
            }

            try {
                address.Street = nav.SelectSingleNode(@"//*[local-name()='street']").Value.Trim();
            } catch (Exception) { address.Street = string.Empty; }

            try {
                address.Number = nav.SelectSingleNode(@"//*[local-name()='houseNumber']").Value.Trim();
            }
            catch (Exception) { address.Number = string.Empty; }

            try {
                address.ZIP = nav.SelectSingleNode(@"//*[local-name()='postcode']").Value.Trim();
            }
            catch (Exception) { address.ZIP = string.Empty; }

            try
            {
                address.City = nav.SelectSingleNode(@"//*[local-name()='city']").Value.Trim();
            }
            catch (Exception) { address.City = string.Empty; }

            try {
                address.Country = nav.SelectSingleNode(@"//*[local-name()='country']").Value.Trim();
            }
            catch (Exception) { address.Country = string.Empty; }

            try
            {
                address.Geohash = nav.SelectSingleNode(@"//*[local-name()='geohash']").Value.Trim();
            }
            catch (Exception) { address.Geohash = string.Empty; }

            try
            {
                address.Score = nav.SelectSingleNode(@"//*[local-name()='score']").Value.Trim();
            }
            catch (Exception) { address.Score = string.Empty; }
            try
            {
                address.Confidence = nav.SelectSingleNode(@"//*[local-name()='confidence']").Value.Trim();
            }
            catch (Exception) { address.Confidence = string.Empty; }

            // admin areas
            try {
                address.State = address.AdminArea1 = nav.SelectSingleNode(@"//*[local-name()='state']").Value.Trim();
            }
            catch (Exception) { address.State = address.AdminArea1 = string.Empty; }

            try {
                address.District = address.AdminArea2 = nav.SelectSingleNode(@"//*[local-name()='district']").Value.Trim();
            }
            catch (Exception) { address.District = address.AdminArea2 = string.Empty; }

            return address;
        }