繁体   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