Esempio n. 1
0
        private async void Load(CityMapProxy city)
        {
            using (var client = new HttpClient())
            {
                var url      = "http://api.openweathermap.org/data/2.5/weather?id=" + city.Id + "&APPID=8e44fd2ad82d53c04469e467010eb7b3&units=metric&lang=es";
                var jsonText = await client.GetStringAsync(url);

                var data = OpenWeatherMapProxy.FromJson(jsonText);

                Description.Text = data.Weather[0].Description;
                Temperature.Text = data.Main.Temp + "°C";



                //LastUpdate.Text = String.Format("{0:G}", (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(data.Dt));
                TemperatureMin.Text = "Min: " + data.Main.TempMin + " °C";
                TemperatureMax.Text = "Max: " + data.Main.TempMax + " °C";
                Temperature.Text    = data.Main.Temp + " °C";
                Pressure.Text       = data.Main.Pressure + " Pascales";
                Humidity.Text       = data.Main.Humidity + " %";


                //Sunrise.Text = String.Format("{0:T}", (new DateTime(1970, 1, 1)).AddSeconds(data.Sys.Sunrise));
                //Sunset.Text = String.Format("{0:T}", (new DateTime(1970, 1, 1)).AddSeconds(data.Sys.Sunset));


                var            iconUrl = "http://openweathermap.org/img/w/" + data.Weather[0].Icon + ".png";
                UriImageSource source  = new UriImageSource();
                source.Uri  = new Uri(iconUrl);
                Logo.Source = source;


                //Logo.Source = ImageSource.FromResource("WeatherApp.Assets.WeatherIcons." + data.Weather[0].Icon + ".png");
            }
        }
        private async void Load()
        {
            using (var client = new HttpClient())
            {
                var geolocUrl  = "http://ip-api.com/json";
                var jsonGeoloc = await client.GetStringAsync(geolocUrl);

                var geoObj = GeoIpMapProxy.FromJson(jsonGeoloc);

                var url      = "http://api.openweathermap.org/data/2.5/weather?lat=" + geoObj.Lat + "&lon=" + geoObj.Lon + "&APPID=8e44fd2ad82d53c04469e467010eb7b3&units=metric&lang=es";
                var jsonText = await client.GetStringAsync(url);

                var data = OpenWeatherMapProxy.FromJson(jsonText);

                var tmp = BindingContext as MasterDetailPage1MasterViewModel;
                tmp.MenuItems.Add(new CityMapProxy
                {
                    Id      = (int)data.Id,
                    Name    = data.Name,
                    Country = data.Sys.Country,
                    Coord   = data.Coord
                });

                Location.Text = data.Name;
                //Description.Text = data.Weather[0].Description;
                Temperature.Text = data.Main.Temp + "°C";

                /*
                 * var iconUrl = "http://openweathermap.org/img/w/" + data.Weather[0].Icon + ".png";
                 * UriImageSource source = new UriImageSource();
                 * source.Uri = new Uri(iconUrl);
                 * Icon.Source = source;
                 */

                Icon.Source           = ImageSource.FromResource("WeatherApp.Assets.WeatherIcons." + data.Weather[0].Icon + ".png");
                ListView.SelectedItem = tmp.MenuItems.First();
            }
        }
Esempio n. 3
0
        private async void GetInfo_Clicked(object sender, EventArgs e)
        {
            using (var client = new HttpClient())
            {
                var geolocUrl  = "http://ip-api.com/json";
                var jsonGeoloc = await client.GetStringAsync(geolocUrl);

                var geoObj = GeoIpMapProxy.FromJson(jsonGeoloc);

                var url      = "http://api.openweathermap.org/data/2.5/weather?q=" + City.Text + "&APPID=8e44fd2ad82d53c04469e467010eb7b3";
                var jsonText = await client.GetStringAsync(url);

                var data = OpenWeatherMapProxy.FromJson(jsonText);
                Result.Text = "Nombre estacion: " + data.Name +
                              "\nTemperatura: " + data.Main.Temp +
                              "\nHumedad: " + data.Main.Humidity +
                              "\nDescripcion: " + data.Weather[0].Description;

                var            iconUrl = "http://openweathermap.org/img/w/" + data.Weather[0].Icon + ".png";
                UriImageSource source  = new UriImageSource();
                source.Uri  = new Uri(iconUrl);
                Icon.Source = source;
            }
        }
Esempio n. 4
0
 public static string ToJson(this OpenWeatherMapProxy self) => JsonConvert.SerializeObject(self, Settings);