GetPositionAsync does not return on real device when indoors - Xamarin Android

依然范特西╮ 提交于 2020-01-04 15:29:06

问题


I am developing both and iOS and Android version that requires GPS using Xamarin.

On iOS it's working fine, however now developing the Android version I have some issues with the GPS. It does not fetch the GPS but times out. However, on a emulator (using Genymotion) it fetches a coordinate right away. Note that I am using the Xamarin.Mobile (latest plugin 0.7.5).

    private async Task<HelpPosition> CreateGeolocator ()
    {
        int accuracy = SettingsManager.Instance.GetSettings ().Accuracy;
        Geolocator locator = new Geolocator (this) { DesiredAccuracy = accuracy * 10 };

        Position p = await locator.GetPositionAsync (timeout: 10000);

        return new HelpPosition{ Latitude = p.Latitude, Longitude = p.Longitude };
    }

This always code times out after 10s. I have set the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions.

The issue seems only to occur when indoors. However Google Maps is perfectly fine getting my exact position. And I have checked all settings in Location Services (Use wireless networks and Use GPS satelites). The device is a Samsung Note 2.


回答1:


Never got Xamarin.Mobile working to satisfaction on Android indoors so I tested the only other option in Component Store avaliable: Geolocator. Works like a charm!

https://components.xamarin.com/view/GeolocatorPlugin

Edit It works better, but even with this plugin I get reports that the location received is off. The search for a better solution continues...



来源:https://stackoverflow.com/questions/28797525/getpositionasync-does-not-return-on-real-device-when-indoors-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!