[英]Xamarin Forms Geolocator Continuously Updating the Location
我希望不斷更新設備在Google地圖上的當前位置。
出於各種原因,我必須實現自己的藍點 。 我所做的是:
我隱藏了谷歌地圖的默認我的位置標記( 默認藍點 )。
我畫了自己的藍點
我創建了一個不斷調用Geolocator來更新其當前位置的線程: 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.