private void getWeather(double latitude, double longitude) { string apiKey = "32b0b275eea19d641b0069e91c91b50a"; string apiUrl = "https://api.forecast.io/forecast/" + apiKey + "/" + latitude + "," + longitude; if (isNetworkAvailable()) { RunOnUiThread(() => toggleRefresh()); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().Url(apiUrl).Build(); Call call = client.NewCall(request); call.Enqueue(response => { RunOnUiThread(() => toggleRefresh()); var jsonData = JObject.Parse(response.Body().String()); mCurrentWeather = getCurrentDetails(jsonData); RunOnUiThread(() => updateDisplay()); }, (req, exception) => { ShowError(); }); } else { Toast.MakeText(this, "Network unavailable", ToastLength.Long).Show(); } }
private CurrentWeather getCurrentDetails(JObject jsonData) { string timezone = (string)jsonData ["timezone"]; JObject currentDetails = JObject.FromObject (jsonData ["currently"]); CurrentWeather currentWeather= new CurrentWeather(this); currentWeather.Humidity = (double)currentDetails ["humidity"]; currentWeather.Time = (long)currentDetails ["time"]; currentWeather.Icon = (string)currentDetails ["icon"]; currentWeather.PrecipChance = (double)currentDetails ["precipProbability"]; currentWeather.Summary = (string)currentDetails ["summary"]; currentWeather.Temperature = (double)currentDetails ["temperature"]; currentWeather.TimeZone = timezone; return currentWeather; }
private CurrentWeather getCurrentDetails(JObject jsonData) { string timezone = (string)jsonData ["timezone"]; JObject currentDetails = JObject.FromObject(jsonData ["currently"]); CurrentWeather currentWeather = new CurrentWeather(this); currentWeather.Humidity = (double)currentDetails ["humidity"]; currentWeather.Time = (long)currentDetails ["time"]; currentWeather.Icon = (string)currentDetails ["icon"]; currentWeather.PrecipChance = (double)currentDetails ["precipProbability"]; currentWeather.Summary = (string)currentDetails ["summary"]; currentWeather.Temperature = (double)currentDetails ["temperature"]; currentWeather.TimeZone = timezone; return(currentWeather); }
private void getWeather(double latitude, double longitude) { string apiKey = "32b0b275eea19d641b0069e91c91b50a"; string apiUrl = "https://api.forecast.io/forecast/" + apiKey + "/" + latitude + "," + longitude; if (isNetworkAvailable ()) { RunOnUiThread(() => toggleRefresh()); OkHttpClient client = new OkHttpClient (); Request request = new Request.Builder ().Url (apiUrl).Build (); Call call = client.NewCall (request); call.Enqueue (response => { RunOnUiThread(() => toggleRefresh()); var jsonData = JObject.Parse (response.Body ().String ()); mCurrentWeather = getCurrentDetails (jsonData); RunOnUiThread(() => updateDisplay()); }, (req, exception) => { ShowError (); }); } else { Toast.MakeText (this, "Network unavailable", ToastLength.Long).Show (); } }