Exemplo n.º 1
0
        public List <Location> GetCoordinat(string house, string street, string city)
        {
            Uri dataUri = new Uri(string.Format(geourl, house, street, city));

            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(dataUri);
                request.Method = "GET";
                AdressModel[] Adress;
                using (var response = request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        DataContractJsonSerializer dcs = new DataContractJsonSerializer(typeof(AdressModel[]));
                        Adress = dcs.ReadObject(stream) as AdressModel[];
                    }
                }
                if (Adress == null || Adress.Count() == 0)
                {
                    return(null);
                }
                List <Location> lookups = new List <Location>();
                foreach (AdressModel el in Adress)
                {
                    double       lon = 0, lat = 0;
                    NumberStyles style   = NumberStyles.AllowDecimalPoint;
                    CultureInfo  culture = CultureInfo.InvariantCulture;
                    double.TryParse(el.lat, style, culture, out lat);
                    double.TryParse(el.lon, style, culture, out lon);
                    lookups.Add(new Location(lat, lon));
                }
                return(lookups);
            }
            catch
            {
                return(null);
            }
        }