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();
            }
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
 public static string ToJson(this GeoIpMapProxy self) => JsonConvert.SerializeObject(self, Settings);