问题
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