How to get the current phone location in Xamarin forms

2

I am working with Google Maps and I need to show the user's location on the map, to do this I use a plugin called GeolocatorPlugin by James Montemagno.

The problem is that in the deploy of the application it falls, I think the problem occurs because I'm calling an asynchronous method from my contentpage therefore when asking for the authorization to use the location before pressing allow the application is dropped complete After the application is already on the phone when starting it does not fall, this only happens in the deployment of the application.

The final question is: where can I call this method to run asynchronously? (here is my code)

namespace CustomRenderer
{
    public partial class MapPage : ContentPage
    {
        public MapPage()
        {
            findMeAsync();
        }

        private async System.Threading.Tasks.Task findMeAsync()
        {            
            TimeSpan timeout = new TimeSpan(0, 0, 0, 10);

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var position = await locator.GetPositionAsync(timeout,includeHeading: false); 
        } 
    }      
}
    
asked by Medina Nualart Martin 10.11.2017 в 16:34
source

1 answer

0

You could use the OnApearing method Something like this:

 protected override  async void OnAppearing()
    {
        base.OnAppearing();
        /*Como puedes ver aquí, podemos esperar metodos Async*/
        await DisplayAlert("Prueba", "Este metodo es esperable", "ok");

    }

I hope it helps you!

    
answered by 27.11.2017 в 21:06