Including base location getter

This commit is contained in:
Kira 2023-08-30 15:26:18 -07:00
parent 6e69a37b2b
commit 66059939df
2 changed files with 19 additions and 1 deletions

View File

@ -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<Location> GetCoordinatesAsync(string address)
{
IEnumerable<Location> 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;
}
}
}

View File

@ -9,7 +9,7 @@
<!--Search Bar-->
<Grid>
<Frame/>
<SearchBar Placeholder="Search" VerticalOptions="Center"/>
<SearchBar Placeholder="Search" VerticalOptions="Center" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}"/>
</Grid>
<!-- Title -->
<VerticalStackLayout Grid.Row="1" Style="{StaticResource MainStackLayout}">