Merge pull request #180 from kenwilcox/master

allow the user to set unit of measure.
This commit is contained in:
Frank A. Krueger 2018-08-25 12:49:06 -04:00 committed by GitHub
commit 5e4a3e2d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}
}
}
}
}