delphi 在FireMonkey应用程序中使用TOrientationSensor获取设备倾斜和指南针航向  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 在FireMonkey应用程序中使用TOrientationSensor获取设备倾斜和指南针航向


当TOrientationSensor组件的Active属性设置为True时,将获取信息。

OrientationSensor1.Active := True;
在OnSensorChoosing事件中,指定要使用的传感器。

以下代码检查并选择可以获取设备倾斜度的传感器。

procedure TForm1.OrientationSensor1SensorChoosing(Sender: TObject;
  const Sensors: TSensorArray; var ChoseSensorIndex: Integer);
var
  I: Integer;
begin
  for I := 0 to High(Sensors) do
  begin
    if TCustomOrientationSensor.TProperty.TiltX
      in TCustomOrientationSensor(Sensors[I]).AvailableProperties then
    begin
      ChoseSensorIndex := I;
      Exit;
    end;
  end;
  ChoseSensorIndex := 0;
end;
以下代码检查并选择可以获取指南针航向的传感器。

procedure TForm1.OrientationSensor2SensorChoosing(Sender: TObject;
  const Sensors: TSensorArray; var ChoseSensorIndex: Integer);
var
  I: Integer;
begin
  for I := 0 to High(Sensors) do
  begin
    if TCustomOrientationSensor.TProperty.HeadingX
      in TCustomOrientationSensor(Sensors[I]).AvailableProperties then
    begin
      ChoseSensorIndex := I;
      Exit;
    end;
  end;
  ChoseSensorIndex := 0;
end;
在OnDataChanged事件中,获取传感器信息。

以下代码显示设备倾斜度。

procedure TForm1.OrientationSensor1DataChanged(Sender: TObject);
begin
  LabelTiltX.Text := FloatToStr(OrientationSensor1.Sensor.TiltX);
  LabelTiltY.Text := FloatToStr(OrientationSensor1.Sensor.TiltY);
  LabelTiltZ.Text := FloatToStr(OrientationSensor1.Sensor.TiltZ);
end;
以下代码显示指南针的方向。

procedure TForm1.OrientationSensor2DataChanged(Sender: TObject);
begin
  LabelHeadingX.Text := FloatToStr(OrientationSensor2.Sensor.HeadingX);
  LabelHeadingY.Text := FloatToStr(OrientationSensor2.Sensor.HeadingY);
  LabelHeadingZ.Text := FloatToStr(OrientationSensor2.Sensor.HeadingZ);
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.046976089477539 seconds