Merge pull request #180 from kenwilcox/master
allow the user to set unit of measure.
This commit is contained in:
commit
5e4a3e2d83
|
@ -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" >
|
||||
|
@ -89,4 +91,4 @@
|
|||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
</ContentPage>
|
||||
|
|
|
@ -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
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue