public IList<City> getNames(string searchstring)
        {
            WebRequest request = WebRequest.Create("http://api.geonames.org/search?name=" + searchstring +"&country=SE&type=json&username=jensaronsson");

            WebResponse respons = request.GetResponse();

            Stream stream = respons.GetResponseStream();

            StreamReader reader = new StreamReader(stream);

            string responseFromServer = reader.ReadToEnd();

            JObject obj = JObject.Parse(responseFromServer);

            var geonames = obj["geonames"];

            foreach (var geoname in geonames)
            {
               fcode = (string)geoname["fcode"];

               if (fcode == "PPLA2" || fcode == "PPLC" || fcode == "PPLA" || fcode == "PPL")
               {
                   City city = new City{Name = (string)geoname["toponymName"], State = (string)geoname["adminName1"]};
                    _cities.Add(city);

               }
            }

            return _cities;
        }
Ejemplo n.º 2
0
 public Weather(City city, string cod, string message, int cnt, object list)
 {
     City = city;
     Cod = cod;
     Message = message;
     List = list;
 }