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;

相关阅读 >>

Delphi 2009 查看所有 unicode 字符

Delphi 字符串保存为 txt文件

Delphi getdrivetypea() 查看驱动器类型

Delphi 从 twebbrowser中获得当前输入处的链接

Delphi xe3里判断网络是否连接成功

Delphi下程序内存泄露报告

Delphi 获取自身软件的版本号

Delphi分别连接ms sqlserver、oracle和access数据库的连接字符串

Delphi 获取ie中选项卡标题

Delphi & c++ 安卓使用权限

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...