From 226335d86ed53a71b3856a0020c5e6ded6f8e530 Mon Sep 17 00:00:00 2001 From: James Clancey Date: Thu, 4 Aug 2016 13:31:17 -0700 Subject: [PATCH] Added GetWeatherGps method to the Service --- MyWeather/Services/WeatherService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MyWeather/Services/WeatherService.cs b/MyWeather/Services/WeatherService.cs index e1e0354..ef1d467 100644 --- a/MyWeather/Services/WeatherService.cs +++ b/MyWeather/Services/WeatherService.cs @@ -2,6 +2,9 @@ using System.Net.Http; using System.Threading.Tasks; using static Newtonsoft.Json.JsonConvert; +using System; +using Plugin.Geolocator; +using System.Diagnostics; namespace MyWeather.Services { @@ -32,7 +35,18 @@ public async Task GetWeather(double latitude, double longitude, Uni } - public async Task GetWeather(string city, Units units = Units.Imperial) + public async Task GetWeatherGps (Units units = Units.Imperial) + { + var locator = CrossGeolocator.Current; + locator.DesiredAccuracy = 50; + + var position = await locator.GetPositionAsync (timeoutMilliseconds: 10000); + + return await GetWeather (position.Latitude, position.Longitude,units); + + } + + public async Task GetWeather(string city, Units units = Units.Imperial) { using (var client = new HttpClient()) {