我試圖檢測設備移動的方向。如果拿起設備(手機或平板電腦)并向右或向左移動,我想使用 Flutter 檢測它。
這是我嘗試過的:
我曾嘗試為此使用
如果我非常快速地移動設備,該程式僅顯示向左或向右,盡管我想以較慢的速度檢測方向。為此,我嘗試取較小的值,"event.x"但在這種情況下,即使設備靜止,輸出也會在“左”和“右”和“靜止”之間快速切換。
I could not find any example that covers this problem online or in the package docs or examples.
I would like to know how I can achieve this? I would like to know the left and right movement of the device with slow speeds too.
Should I use another sensor?
I do not fully understand the magnetometer's inputs which I've also tried using. Any help in understanding that is appreciated.
I have also tried searching for a package on pub.dev but I can't find any that fit this need.
Any help is appreciated thanks a lot in advance.
uj5u.com熱心網友回復:
該插件會告訴您關于加速的資訊。如果您想檢測運動,即速度,您需要將積分過濾器應用于來自這些事件的資料。您可能想要使用UserAccellerationEvents,因為它們已經消除了重力。
此外,使用來自陀螺儀的事件將使您的計算更加穩健。
順便說一下,這是傳感器融合的一個應用。
uj5u.com熱心網友回復:
您可以嘗試使用位置包訪問設備當前位置。它具有標題屬性,對您很有用。您可以使用偵聽器來捕獲設備位置更改。無論何時更改設備標題,都會列印標題值。
Location location = Location();
location.onLocationChanged.listen((LocationData currentLocation) {
// Use current location
print(currentLocation.heading);
});
在此處閱讀更多資訊:https : //pub.dev/packages/location
航向是一個雙精度值,從 0 到 360 度變化。此影像將幫助您了解航向值的含義。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/360810.html
標籤:flutter dart flutter-dependencies right-to-left direction
