allow the user to set unit of measure.

This commit is contained in:
Ken Wilcox 2018-06-29 09:30:18 -06:00
parent efc7bc2676
commit 8806bc0d7b
3 changed files with 7 additions and 5 deletions

View File

@ -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);

View File

@ -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" >
@ -89,4 +91,4 @@
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
</ContentPage>

View File

@ -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;
@ -28,4 +28,4 @@ namespace WeatherApp
}
}
}
}
}