Geolocator Xamarin Plugin

1

I need to get the current location of the user's device and with this to help me I'm using the Xamarin Geolocator Plugin, I can get the current location normally on my smartphone but the Google emulator does not pick up the current location even with GPS configured to the city of Rio de Janeiro, and the strange thing is that it always points to Rome.

Android location permissions are enabled and everything is set up correctly. For this I used as a basis this project link .

Follow the code on my page:

Builder:

Public MapsPage()
{
    InitializeComponent();

    var position = PosicaoAtualAsync();
    map.MoveToRegion(MapSpan.FromCenterAndRadius(position.Result, Distance.FromMeters(50)));
}

CurrentAsync Method:

async Task<Position> PosicaoAtualAsync()
    {
        var locator = CrossGeolocator.Current;


        if (locator.IsGeolocationEnabled && locator.IsGeolocationAvailable)
        {
            locator.DesiredAccuracy = 100;
            if (!locator.IsListening)
                await locator.StartListeningAsync(1000, 1000);

            var position = await locator.GetPositionAsync(timeoutMilliseconds: 1000);

            if (position != null)
            {
                return new Position(position.Latitude, position.Longitude);
            }
        }

        await DisplayAlert("Ops", "Não conseguimos obter sua localização, por favor, verifique sua conexão e se o seu GPS está ativo.", "OK");
        return new Position(0, 0);

    }
    
asked by anonymous 17.03.2017 / 19:52

0 answers