Including base location getter
This commit is contained in:
parent
6e69a37b2b
commit
66059939df
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}">
|
||||
|
|
Loading…
Reference in New Issue