简体   繁体   中英

Xamarin XLabs Geolocator not working on Android

I have access fine and coarse location checked in the manifest file and first time the application runs on the android emulator (Android_Accelerated_x86 (Android 7.1 - API 25)) it logs the latitude. But if I deploy the app for the second time, third time and so on it runs endlessly even though the timeout is 10000 ms (no Exception thrown). If I close and open the emulator and deploy the app again it works again and so on. Any ideas on how to fix this?

public static class NetworkingTools
{
    private static IGeolocator locator = Resolver.Resolve<IGeolocator>();

    static NetworkingTools()
    {
        locator.DesiredAccuracy = 50;
        locator.StartListening(2000, 0, true);
        GetPosition();
    }

    public async static void GetPosition()
    {
        var position = await locator.GetPositionAsync(10000);
        System.Diagnostics.Debug.WriteLine(position.Latitude);
    }
}

Please note the remark they have on their GitHub page:

NOTICE: This project is no longer maintained. It may not work with newer versions of Xamarin.Forms.

I think it is unwise to integrate this into your project if you have the choice. Instead have a look at the Geolocator Plugin by James Montemagno.

I was having the same issue, but apparently that's the way the emulators work. There is no problem with the code, you have to open the EMULATOR Settings, go to Location and Click SEND.

More details here:

Getting Location on Android Emulator more then once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM