Hola amigos estoy tratando de obtener la geolocaliacion de mi telefono con Xamarin.Maps.Forms y Mvvm , pero me sale este error. Entiendo que no puedo convertir el metodo como tal en una position, pero entonces alguien sabe como traerlo de mi view model a mi page.cs ??
Este es mi codigo
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MapPage : ContentPage
{
private MapPageViewModel _viewModel;
public MapPage()
{
InitializeComponent();
BindingContext = _viewModel = new MapPageViewModel();
}
protected override void OnAppearing()
{
base.OnAppearing();
var currentLocation = _viewModel.GetCurrentLocationCommand;
EJMap.Pins.Clear();
Pin Current = new Pin()
{
Position = currentLocation, //aqui esta el error de arriba
};
}
}
Este es mi view model
public class MapPageViewModel
{
#region props
public ICommand GetCurrentLocationCommand { get; set; }
#endregion
public MapPageViewModel()
{
GetCurrentLocationCommand = new Command(async ()=> await GetCurrentLocationCommandExecute());
}
public async Task<Position> GetCurrentLocationCommandExecute()
{
Position currentPosition = new Position();
CancellationTokenSource cts;
try
{
var location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
currentPosition = new Position(location.Latitude, location.Longitude);
}
else
{
var request = new GeolocationRequest(GeolocationAccuracy.High, TimeSpan.FromSeconds(10));
cts = new CancellationTokenSource();
var currentLocation = await Geolocation.GetLocationAsync(request, cts.Token);
if (currentLocation != null)
{
currentPosition = new Position(currentLocation.Latitude, currentLocation.Longitude);
}
}
}
catch (Exception)
{
throw;
}
return currentPosition;
}
}