我正在使用此处找到的 CrossGeeks Geofence 插件: https ://github.com/CrossGeeks/GeofencePlugin 使用主页上的文档和此处找到的示例来构建测试应用程序: https ://github.com/domaven/xamarin -插件/树/主/样本/地理围栏
当我尝试开始监视区域时遇到此错误:
{System.NullReferenceException: Object reference not set to an instance of an object.
at Plugin.Geofence.GeofenceImplementation.RequestMonitoringStart () [0x00000] in <793ebe419a94494388f459127f8240ff>:0
at Plugin.Geofence.GeofenceImplementation.StartMonitoring (Plugin.Geofence.GeofenceCircularRegion region) [0x00061] in <793ebe419a94494388f459127f8240ff>:0
at GeoFenceApp.MainPageViewModel.StartStopMonitoring () [0x00027] in C:\Users\ctodd\source\repos\GeoFenceApp\GeoFenceApp\MainPageViewModel.cs:87 }
CrossGeofence 对象本身不为空,_myRegion 对象也不是: screenshot of cross geofence object screenshot of region object 我相信我根据文档和示例正确初始化了事物。我正在使用以下权限,尽管我认为只有 fine_location、coarse_location、read_gservices 和 boot_completed 是必需的:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
示例中需要 google api 密钥,因为正在显示地图,但我不需要显示地图。我还需要这个密钥来访问定位服务吗?获得权限后,我真的不确定是什么导致了错误,因为我试图按照文档进行操作。