簡體   English   中英

如何從 Xamarin.Forms 獲得連續的地理定位?

[英]How can I get a continous geolication from Xamarin.Forms?

我正在嘗試使用 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;

        });

主要方法過程:

...

Location location = new Location();

location = await Geolocation.GetLocationAsync(request);

...

如果我將此行為與另一個使用 GPS 位置的應用程序進行比較,則只需激活 GPS 信號一次即可。 我做錯了什么?

這些是結果:

搜索 GPS

有源模塊

據我所知, Xamarin.Essentials沒有位置偵聽器來檢測背景中的位置變化。 一個解決方案是使用 jamesmontemagno 的Geolocator 插件

這是有關如何使用它的示例( 來源

async Task StartListening()
{
    await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 10, true, new Plugin.Geolocator.Abstractions.ListenerSettings
    {
        ActivityType = 
        Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
        AllowBackgroundUpdates = true,
        DeferLocationUpdates = true,
        DeferralDistanceMeters = 1,
        DeferralTime = TimeSpan.FromSeconds(1),
        ListenForSignificantChanges = true,
        PauseLocationUpdatesAutomatically = false
    });
    CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
}

private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e)
{
    Device.BeginInvokeOnMainThread(() =>
    {
        var Position = e.Position;
    });
} 

如何從列表中獲取密鑰<object>在 Firebase 在 Xamarin.Forms 中?<div id="text_translate"><p> I am programming in Xamarin.Forms, I am also using the FirebaseDatabase [dot] net Nuget I have the following method, in connection to my Firebase Realtime Database, which sends a List.</p><pre> public static async Task&lt;bool&gt; PostDetallePedido(List&lt;AgregarCarrito&gt; carrito) { try { var result = await firebase.Child("DetallePedidos").Child(Preferences.Get("idOrder", string.Empty)).PostAsync(carrito); result2 = result.Key; var keyTable = new KeyClass() { keyU = result2, orderId = Preferences.Get("idOrder", string.Empty) }; await firebase.Child("keyTable").Child(Preferences.Get("idOrder", string.Empty)).PostAsync(keyTable); return true; } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return false; } }</pre><p> 我的數據庫填充如下<a href="https://i.stack.imgur.com/pBxxr.png" rel="nofollow noreferrer">圖1</a></p><p> 使用前面的代碼,我可以獲得唯一 ID,但我仍然不知道如何獲取以自動增量方式生成的值</p><pre>-M7B6xMB19uodzf-C71H | -0 | -1</pre><p> <strong>編輯:</strong></p><pre> public static async Task&lt;List&lt;AgregarCarrito&gt;&gt; GetDetailByUser(int id) { try { var key = await GetKey(id); var value = (await firebase.Child("DetallePedidos").Child(Convert.ToString(id)).Child(key.keyU).OnceAsync&lt;AgregarCarrito&gt;()).Select(item =&gt; new AgregarCarrito { orderId = item.Object.orderId, ProductName = item.Object.ProductName, CustomerId = item.Object.CustomerId, Price = item.Object.Price, TotalAmount = item.Object.TotalAmount, ProductId = item.Object.ProductId, Qty = item.Object.Qty, imageUrl = item.Object.imageUrl, Valor = item.Object.Valor }).ToList(); return value; } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return null; } }</pre><p> 我創建了一個使用 orderId 返回鍵值的方法,但我仍然無法訪問列表的值,在這種情況下,這將是發送列表時以自動增量方式生成的對象</p><p><a href="https://i.stack.imgur.com/ENEas.png" rel="nofollow noreferrer">圖 2</a></p></div></object>

[英]How can I get a key from a List <object> in Firebase in Xamarin.Forms?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 如何從列表中獲取密鑰<object>在 Firebase 在 Xamarin.Forms 中?<div id="text_translate"><p> I am programming in Xamarin.Forms, I am also using the FirebaseDatabase [dot] net Nuget I have the following method, in connection to my Firebase Realtime Database, which sends a List.</p><pre> public static async Task&lt;bool&gt; PostDetallePedido(List&lt;AgregarCarrito&gt; carrito) { try { var result = await firebase.Child("DetallePedidos").Child(Preferences.Get("idOrder", string.Empty)).PostAsync(carrito); result2 = result.Key; var keyTable = new KeyClass() { keyU = result2, orderId = Preferences.Get("idOrder", string.Empty) }; await firebase.Child("keyTable").Child(Preferences.Get("idOrder", string.Empty)).PostAsync(keyTable); return true; } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return false; } }</pre><p> 我的數據庫填充如下<a href="https://i.stack.imgur.com/pBxxr.png" rel="nofollow noreferrer">圖1</a></p><p> 使用前面的代碼,我可以獲得唯一 ID,但我仍然不知道如何獲取以自動增量方式生成的值</p><pre>-M7B6xMB19uodzf-C71H | -0 | -1</pre><p> <strong>編輯:</strong></p><pre> public static async Task&lt;List&lt;AgregarCarrito&gt;&gt; GetDetailByUser(int id) { try { var key = await GetKey(id); var value = (await firebase.Child("DetallePedidos").Child(Convert.ToString(id)).Child(key.keyU).OnceAsync&lt;AgregarCarrito&gt;()).Select(item =&gt; new AgregarCarrito { orderId = item.Object.orderId, ProductName = item.Object.ProductName, CustomerId = item.Object.CustomerId, Price = item.Object.Price, TotalAmount = item.Object.TotalAmount, ProductId = item.Object.ProductId, Qty = item.Object.Qty, imageUrl = item.Object.imageUrl, Valor = item.Object.Valor }).ToList(); return value; } catch (Exception e) { Debug.WriteLine($"Error:{e}"); return null; } }</pre><p> 我創建了一個使用 orderId 返回鍵值的方法,但我仍然無法訪問列表的值,在這種情況下,這將是發送列表時以自動增量方式生成的對象</p><p><a href="https://i.stack.imgur.com/ENEas.png" rel="nofollow noreferrer">圖 2</a></p></div></object> 如何在 xamarin.forms 中獲取應用程序本身的目錄 如何在NUnit Library項目中使用Xamarin.Forms? 如何在Xamarin.Forms中更改頁面? 如何在 Xamarin.Forms 中渲染.obj model? 如何檢測 Xamarin.Forms 中的選項卡按鈕的點擊? 如何從 Xamarin.Forms 中的 UWP 訪問 PCL 中的參數 如何從對象中獲取 Xamarin.Forms 元素的名稱? 如何在Xamarin.Forms中為ToolbarItem創建自定義渲染器? 如何在Xamarin.Forms中為輪播實現活動指示器?
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM