FMX.OrientationSensor Sample
This sample demonstrates how to use the TOrientationSensor component in order to get compass related information such as the tilt on the three axis and the heading on the three axis.
Contents
Location
You can find the OrientationSensor sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
Object Pascal\Mobile Snippets\OrientationSensor
CPP\Mobile Snippets\OrientationSensor
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
The OrientationSensor sample demonstrates how to use the orientation sensor in iOS or Android applications. The sample uses the TOrientationSensor component and the TCustomOrientationSensor class to offer information about the rotation angle (tilt) and the compass heading relative to the magnetic north (heading).
- Note: The TCustomOrientationSensor class supports Android, iOS and Windows platforms. However, each platform provides different orientation sensors and each type of sensor supports a different set of properties (see platform support for a completed list of platform, sensors and supported properties).
How to Use the Sample
- Navigate to one of the locations given above and open:
- Delphi: OrientationSensor.dproj.
- C++: OrientationSensor.cbproj.
- Select the target platform, iOS and Android supported.
- Press F9 or choose Run > Run.
- Interact with the sample:
- Press the Tilt button. It shows:
- The rotation angle in degrees on the X axis.
- The rotation angle in degrees on the Y axis.
- The rotation angle in degrees on the Z axis.
- Press the Heading button. It shows:
- The X coordinate of the vector that points to the magnetic North, measured in MicroTeslas.
- The Y coordinate of the vector that points to the magnetic North, measured in MicroTeslas.
- The Z coordinate of the vector that points to the magnetic North, measured in MicroTeslas.
- Press the Tilt button. It shows:
Files
File in Delphi | File in C++ | Contains |
---|---|---|
OrientationSensor.dproj |
OrientationSensor.cbproj |
The project itself. |
uMain.fmx |
uMain.fmx |
The main form where the components are located. |
uMain.pas |
OrientationSensorPCH.h, OrientationSensor.cpp |
Used to define and implement the sample. |
Information.txt |
Information.txt |
Further information about the sample. |
Classes
TOrientationSensorForm is the main form that represents the main window of the sample. It contains the following components:
- A TLayout object containing two TSpeedButton objects.
- TSpeedButton1 called TiltButton.
- TSpeedButton1 called HeadingButton.
- A TListBox object containing seven TListBoxItem objects.
- TListBoxItem1, called lbOrentationSensor, containing a TSwitch object, called swOrientationSensorActive.
- TListBoxItem2, called lbTiltX.
- TListBoxItem3, called lbTiltY.
- TListBoxItem4, called lbTiltZ.
- TListBoxItem5, called lbHeadingX.
- TListBoxItem6, called lbHeadingY.
- TListBoxItem7, called lbHeadingZ.
- A TOrientationSensor object.
- A TTimer object.
- A ToolBar object with a TLabel object.
Implementation
- The sample uses TOrientationSensor to give information about the device inclination and compass heading.
- The sample uses TSwitch to provide the user with a two-way on-off switch. TSwitch on enables TOrientationSensor.
- The sample uses TTimer to repeat specific actions after a given time interval. TTimer specifies the time interval in which TOrientationSensor offers information to the user.
- The sample uses TListBox to display a list with a set of items with orientation information.
- The sample uses TLayout to organize the Tilt and Heading buttons under the same parent.
- The sample uses TSpeedButton to enable the orientation sensor to offer tilt related information or heading related information.
When you run the application, TOrientationSensor is disabled. You can enable the orientation sensor by switching the swOrientationSensorActive. If TOrientationSensor is enabled, the sample offers some orientation related information depending on which button is pressed. If you press the Tilt button, the sample offers information about the rotation angle. If you press the Heading button, the sample offers information about the compass heading relative to the magnetic north.
Uses
See Also
Samples
- FireMonkey Sensor Info sample
- FireMonkey Accelerometer sample
- FireMonkey Location Demo sample
- FireMonkey Gyroscope sample
- VCL Sensors sample