allow the user to set unit of measure.
This commit is contained in:
parent
efc7bc2676
commit
8806bc0d7b
|
@ -5,12 +5,12 @@ namespace WeatherApp
|
|||
{
|
||||
public class Core
|
||||
{
|
||||
public static async Task<Weather> GetWeather(string zipCode)
|
||||
public static async Task<Weather> GetWeather(string zipCode, string units = "kelvin")
|
||||
{
|
||||
//Sign up for a free API key at http://openweathermap.org/appid
|
||||
string key = "fc9f6c524fc093759cd28d41fda89a1b";
|
||||
string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
|
||||
+ zipCode + "&appid=" + key;
|
||||
+ zipCode + "&appid=" + key + "&units=" + units;
|
||||
|
||||
var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
FontSize="Medium" />
|
||||
<Label x:Name="zipCodeLabel" Text="Zip Code" Style="{StaticResource labelStyle}" />
|
||||
<Entry x:Name="zipCodeEntry" />
|
||||
<Label x:Name="unitOfMeasureLabel" Text="Unit Of Measure" Style="{StaticResource labelStyle}" />
|
||||
<Entry x:Name="unitOfMeasure" Placeholder="kelvin (default), metric, imperial"/>
|
||||
</StackLayout>
|
||||
<StackLayout Padding="0,0,0,10" VerticalOptions="End">
|
||||
<Button x:Name="getWeatherBtn" Text="Get Weather" WidthRequest="185" BorderWidth="1" >
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace WeatherApp
|
|||
{
|
||||
if (!String.IsNullOrEmpty(zipCodeEntry.Text))
|
||||
{
|
||||
Weather weather = await Core.GetWeather(zipCodeEntry.Text);
|
||||
Weather weather = await Core.GetWeather(zipCodeEntry.Text, unitOfMeasure.Text);
|
||||
if (weather != null)
|
||||
{
|
||||
this.BindingContext = weather;
|
||||
|
|
Loading…
Reference in New Issue