private async Task <Tuple <WeatherApiResonseData, OneCallWeatherAPIResponseData> > SearchLocation(string searchInput) { WeatherApiResonseData weather = new WeatherApiResonseData(); OneCallWeatherAPIResponseData weatherDetails = new OneCallWeatherAPIResponseData(); if (searchInput.Any(char.IsDigit)) { try { weather = await OpenWeatherService.GetCurrentWeatherByZipCodeAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } catch (Exception ex) { Debug.Write(ex.Message); weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } } else { weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } return(Tuple.Create(weather, weatherDetails)); }
private async Task <Tuple <WeatherApiResonseData, OneCallWeatherAPIResponseData> > GetLocation() { IGeolocator locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; Position positions = await locator.GetPositionAsync(timeout : new TimeSpan(10000)); IEnumerable <Address> address = await locator.GetAddressesForPositionAsync(positions); WeatherApiResonseData weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(address.FirstOrDefault().Locality); OneCallWeatherAPIResponseData weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); return(Tuple.Create(weather, weatherDetails)); }