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 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
|
//Sign up for a free API key at http://openweathermap.org/appid
|
||||||
string key = "fc9f6c524fc093759cd28d41fda89a1b";
|
string key = "fc9f6c524fc093759cd28d41fda89a1b";
|
||||||
string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
|
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);
|
var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
FontSize="Medium" />
|
FontSize="Medium" />
|
||||||
<Label x:Name="zipCodeLabel" Text="Zip Code" Style="{StaticResource labelStyle}" />
|
<Label x:Name="zipCodeLabel" Text="Zip Code" Style="{StaticResource labelStyle}" />
|
||||||
<Entry x:Name="zipCodeEntry" />
|
<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>
|
||||||
<StackLayout Padding="0,0,0,10" VerticalOptions="End">
|
<StackLayout Padding="0,0,0,10" VerticalOptions="End">
|
||||||
<Button x:Name="getWeatherBtn" Text="Get Weather" WidthRequest="185" BorderWidth="1" >
|
<Button x:Name="getWeatherBtn" Text="Get Weather" WidthRequest="185" BorderWidth="1" >
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace WeatherApp
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(zipCodeEntry.Text))
|
if (!String.IsNullOrEmpty(zipCodeEntry.Text))
|
||||||
{
|
{
|
||||||
Weather weather = await Core.GetWeather(zipCodeEntry.Text);
|
Weather weather = await Core.GetWeather(zipCodeEntry.Text, unitOfMeasure.Text);
|
||||||
if (weather != null)
|
if (weather != null)
|
||||||
{
|
{
|
||||||
this.BindingContext = weather;
|
this.BindingContext = weather;
|
||||||
|
|
Loading…
Reference in New Issue