diff --git a/MAUI_Weather/MVVM/ViewModels/WeatherViewModel.cs b/MAUI_Weather/MVVM/ViewModels/WeatherViewModel.cs index 43856a3..3321a1d 100644 --- a/MAUI_Weather/MVVM/ViewModels/WeatherViewModel.cs +++ b/MAUI_Weather/MVVM/ViewModels/WeatherViewModel.cs @@ -3,10 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace MAUI_Weather.MVVM.ViewModels { public class WeatherViewModel { + + public ICommand SearchCommand => new Command(async (searchText) => + { + var location = await GetCoordinatesAsync(searchText.ToString()); + }); + private async Task GetCoordinatesAsync(string address) + { + IEnumerable locations = await Geocoding.Default.GetLocationsAsync(address); + + Location location = locations?.FirstOrDefault(); + + if (location != null) + { + Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}"); + } + return location; + } } } diff --git a/MAUI_Weather/MVVM/Views/WeatherView.xaml b/MAUI_Weather/MVVM/Views/WeatherView.xaml index 93b2c4f..1188fb5 100644 --- a/MAUI_Weather/MVVM/Views/WeatherView.xaml +++ b/MAUI_Weather/MVVM/Views/WeatherView.xaml @@ -9,7 +9,7 @@ - +