The Android platform provides two sensor terms to determine the location of the device, these two sensors are magnetic field sensors and directional sensors. The Android platform also provides sensors (proximity sensors) that measure the distance from the front of a device to a nearby object. magnetic field sensors and proximity sensors are based on hardware sensors.
Purpose: It is possible to combine magnetic field sensors and accelerometers to measure the position of the device relative to the geomagnetic North Pole, and to use the direction sensor to determine the position of the current device relative to its own reference frame.
Both the magnetic field sensor and the direction sensor return three values, and the proximity sensor returns a value.
Meaning of the direction three values:
Event.valuss[0]: The angle of rotation around the z axis. If the y-axis is on the north, the value is 0. If you point east, the value is 90, and if the y-axis points to the West, the value is 270.
EVENT.VALUSS[1]: The degree of rotation around the x-axis. If the z-axis is positive toward the y-axis positive direction, the value is positive and vice versa. The value varies between 180 and 180.
EVENT.VALUSS[2]: The degree of rotation around the y-axis. When the positive direction of the x-axis is positive from the z-axis, the value is positive and the inverse is negative. The value varies between 180 and 180.
Use the same as the accelerometer sensor.
Advanced Article-Android system: 5. Android Phone position sensor