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.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace MAUI_Weather.MVVM.ViewModels
|
namespace MAUI_Weather.MVVM.ViewModels
|
||||||
{
|
{
|
||||||
public class WeatherViewModel
|
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-->
|
<!--Search Bar-->
|
||||||
<Grid>
|
<Grid>
|
||||||
<Frame/>
|
<Frame/>
|
||||||
<SearchBar Placeholder="Search" VerticalOptions="Center"/>
|
<SearchBar Placeholder="Search" VerticalOptions="Center" SearchCommand="{Binding SearchCommand}" SearchCommandParameter="{Binding Source={x:Reference searchBar}, Path=Text}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
<VerticalStackLayout Grid.Row="1" Style="{StaticResource MainStackLayout}">
|
<VerticalStackLayout Grid.Row="1" Style="{StaticResource MainStackLayout}">
|
||||||
|
|
Loading…
Reference in New Issue