【发布时间】:2019-10-21 15:51:08
【问题描述】:
我正在尝试使用 Xamarin Essentials 连续获取设备的位置,但他的行为很奇怪。每次我使用 GetLocationAsync 方法(就像闪烁模式)时,GPS 信号都会被激活和禁用。
这是我的代码:
主线程:
Xamarin.Forms.Device.StartTimer(TimeSpan.FromMilliseconds(gpsFrequencyRead, () =>
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
{
if (!isBusy)
{
isBusy = true;
await MainMethodProcess();
isBusy = false;
}
});
return activeMainTimer;
});
MainMethodProcess:
...
Location location = new Location();
location = await Geolocation.GetLocationAsync(request);
...
如果我将此行为与另一个使用 GPS 定位的应用程序进行比较,则只需激活一次 GPS 信号即可。我做错了什么?
这些是结果:
【问题讨论】:
-
您使用的是 Xamarin.Essentials 对吗?我认为 Essentials 没有位置变化的监听器,但 CrossGeolocator 有!我将发布一个带有一些代码+源代码的anwser
标签: c# xamarin xamarin.forms geolocation location