public async Task TestGetWeatherAroundPositionAll()
        {
            //lat 47.453991 - long 15.27019: Kapfenberg
            var position = new Geoposition()
            {
                lat = 47.453991,
                lon = 15.27019
            };
            var locations = await s.GetWeatherAroundPosition(position, 20);

            //14 = 20 lt. Parameter - doppelte Ortsnamen => Kann sich u.U. ändern
            Assert.AreEqual(20, locations.Count);
        }
Exemplo n.º 2
0
        public async Task<IList<DayWeather>> GetWeatherAroundPosition(Geoposition position, int maxCnt)
        {
            Uri serviceUrl = new Uri(BASE_URL, $"find?lat={position.lat}&lon={position.lon}&cnt={maxCnt}&units=metric&lang={GetLangForApi()}&appid={API_KEY}");
            Debug.WriteLine($"Start download weather from: {serviceUrl.AbsoluteUri}");
            string jsonStr = await ServiceManager.DownloadService.Load(serviceUrl);

            JObject json = JObject.Parse(jsonStr);
            HashSet<string> incluedCityNames = new HashSet<string>();
            IList<DayWeather> weather = new List<DayWeather>();

            foreach (var city in json["list"])
            {
                Location location = new Location()
                {
                    CityID = city["id"].Value<int?>(),
                    Name = city["name"].Value<string>(),
                    Position = new Geoposition()
                    {
                        lat = city["coord"]["lat"].Value<double>(),
                        lon = city["coord"]["lon"].Value<double>()
                    }
                };
                if (!incluedCityNames.Contains(location.Name))
                {
                    weather.Add(new DayWeather()
                    {
                        Location = location,
                        Day = FromIntervalSince1970(city["dt"].Value<double>()),
                        Code = city["weather"][0]["id"].Value<int>().ToString(),
                        Name = city["weather"][0]["main"].Value<string>(),
                        Description = city["weather"][0]["description"].Value<string>(),
                        Temp = city["main"]["temp"].Value<double>()
                    });
                    incluedCityNames.Add(location.Name);
                }
            }

            return weather;
        }
Exemplo n.º 3
0
 private Task<IList<DayWeather>> GetUpcomingWeatherForPosition(Geoposition position)
 {
     Uri serviceUrl = new Uri(BASE_URL, $"forecast/daily?lat={position.lat}&lon={position.lon}&units=metric&lang={GetLangForApi()}&appid={API_KEY}");
     return GetCityWeatherData(serviceUrl);
 }