Location sensor Overview
The Android platform provides two sensors to determine the location of the device. These two sensors are magnetic field sensors and direction sensors. The Android platform also provides a sensor (proximity sensor) that measures the distance from the front of a device to a neighboring object ). Magnetic field sensors and adjacent sensors are hardware-based sensors. Most Android phones and tablets have magnetic sensors. Adjacent sensors are usually common in mobile phones. This sensor can be used to test how far the screen is from the face when the phone is answered. You can complete some work when answering the call close to your ears. The direction sensor is based on software. The returned data of the sensor comes from the acceleration sensor and the magnetic field sensor.
Role of location sensor
Location Sensors are useful for determining the physical location of a device in the real world. For example, you can combine a magnetic field sensor and an accelerometer to measure the position of the device relative to the geomagnetic Arctic. You can also use a direction sensor to determine the position of the current device relative to its own reference system.
Both the magnetic field sensor and the direction sensor return three values (sensorevent. values), while the adjacent sensor returns only one value.
Direction Sensor
Sensorevent. Values [0]:
The angle of rotation around the Z axis. If the Y axis (normally in the direction of the mobile phone) is facing the north, the value is 0. If the Y axis points to the south, the value is 180, and the Y axis points to the east. The value is 90, if the Y axis points to the west, the value is 270.
Sensorevent. Values [1]:
Degrees that rotate around the X axis. When the orientation from the positive side of the Z axis to the positive side of the Y axis, the value is positive. Otherwise, it is a negative value. The value ranges from 180 to-180.
Sensorevent. Values [2]:
Degrees that rotate around the Y axis. If the direction is from the positive side of the Z axis to the positive side of the X axis, the value is positive. Otherwise, it is a negative value. The value ranges from 180 to-180.
Magnetic Field Sensor
Sensorevent. Values [0]:
Magnetic Force along the X axis (μT, millitesla)
Sensorevent. Values [1]:
Magnetic forces along the Y axis (μ T, millitesla)
Sensorevent. Values [2]:
Magnetic forces along the Y axis (μ T, millitesla)
Adjacent Sensor
Sensorevent. Values [0]:
Distance from the front of the mobile phone to the physical proximity (cm)
Demo