【发布时间】:2018-11-13 10:26:16
【问题描述】:
我正在使用 Xamarin.Forms 并处理将在 Android 和 Iphone 中运行的项目。我的项目结构(如果该信息有用?)是同一解决方案中的三个项目“MyApp”、“MyApp.Android”和“MyApp.iOS”。
现在我正在使用不同的插件,例如 Xam.Plugin.Geolocator 和 Plugin.Geofencing.Eddy 来使用地理围栏,但我遇到了一些问题(如另一个问题 Geofence for xamarin crossplatform 中所述)。
现在我想检查地理围栏是否能够工作,检查 GPS_PROVIDER 和 NETWORK_PROVIDER 是否可用,我该如何实现?现在我只能检查位置是否启用,但不能检查哪个提供商。
public bool IsLocationAvailable()
{
if (!CrossGeolocator.IsSupported)
return false;
if (!CrossGeolocator.Current.IsGeolocationEnabled)
return false;
if (!CrossGeolocator.Current.IsGeolocationAvailable)
return false;
if (!CrossGeofencing.IsSupported)
return false;
return true;
}
现在,如果位置提供程序设置为“仅限 GPS”,它会因此引发错误,但我不知道如何捕获和处理它。我已经看到了一些其他示例和问题,但仅适用于 android,如果我已经在使用这些插件并且主要在 xamarin 表单项目(又名“MyApp”)而不是 android 项目(“ MyApp.Android")
抱歉,图片太大了,我不知道如何调整它的大小!
【问题讨论】:
标签: android xamarin xamarin.forms gps geofencing