我希望不断更新设备在 Google map 上的当前位置。
由于各种原因,我必须实现自己的蓝点。我所做的是:
我隐藏了 Google map 的默认我的位置标记(默认蓝点)。
我画了自己的蓝点
我创建了一个不断调用 Geolocator 以更新其当前位置的线程:
/li>await locator.GetPositionAsync(TimeSpan.FromSeconds(2), null, false);
但是,位置更新需要很长的延迟。我希望以非常低的间隔(大约 50 毫秒)更新位置,这可能会在设备移动时提供与 Google map 的原始蓝点类似的结果。
我怎样才能做到这一点?
最佳答案
我发现 CrossGeolocator
有一个监听功能,如果有位置更新,它会提示。此函数不会持续调用当前位置,而是会持续监听任何位置变化。
if (CrossGeolocator.IsSupported &&
CrossGeolocator.Current.IsGeolocationAvailable &&
CrossGeolocator.Current.IsGeolocationEnabled)
{
CrossGeolocator.Current.PositionChanged += HandlePositionChanged;
await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(1), 10);
}
关于c# - Xamarin Forms Geolocator 持续更新位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50099890/