2016-07-07 7 views
0

私はxamarinによって開発されたクロスプレート・アプリケーションの磁場データを取得しようとします。私はモバイル開発、特にXamarinでかなり初心者です。 だから私は、こんにちはWordのコードがあります。Device Motion Pluginを使用して、xamarinで磁力計の値を取得するにはどうすればよいですか?

public App() 
     { 
      // The root page of your application 
       MainPage = new ContentPage { 

      Content = new StackLayout {   
        VerticalOptions = LayoutOptions.Center, 
        Children = { 
         new Label { 

          XAlign = TextAlignment.Center, 
         Text = "Welcome to Xamarin Forms!" 
         } 
        } 
       } 

      }; 


     } 

をそして私は、最初のページでmagnetometreの3つの座標値を表示したいです。

Device Motion Pluginはマルチフォームプラグインですが、このコードもありますが、これらの値をアプリケーションに表示する方法はわかりません。

 CrossDeviceMotion.Current.Start(MotionSensorType.Magnetometer); 
     CrossDeviceMotion.Current.SensorValueChanged += (s, a) => 
     { 

      switch (a.SensorType) 
      { 

       case MotionSensorType.Magnetometer: 
        Debug.WriteLine("A: {0},{1},{2}", ((MotionVector)a.Value).X, ((MotionVector)a.Value).Y, ((MotionVector)a.Value).Z); 

        break; 

      } 
     }; 

答えて

0

これを機能させるには、ラベルのx:Name属性を設定する必要があります。私は加速度計を使用しているので、私の名前はaccelerometerLogです。

accelerometerLog.Text = String.Format(
    "X:{0} Y:{1} Z:{2}", 
    ((MotionVector)a.Value).X, 
    ((MotionVector)a.Value).Y, 
    ((MotionVector)a.Value).Z 
); 
:あなたは次の操作を行うことができます。コードから次に

関連する問題