Possible to get device facing?

Trying to figure out how to get the rotation the device is facing in the real world, similar to that of a north/east/south/west.

The goal is to have a “Tracking” app, almost like a “hide&seek” using latitude/longitude. When the device is facing the latitude/longitude the texture will be green, then when it’s not it will fade to shades of red depending on the rotation.

Wanting to have it so I can place various places in the world using longitude/latitude and if the user faces it with their device a certain effect can happen.

Android sensor is called: geomagnetic field sensor

if it is “facing” something then it has a rotation representation.
you could just get the device’s world euler angles:

Vector3 angles= device.transform.rotation.eulerAngles;

then analize the angles.y values.
It should range from 0 to 360.
y angles between 0 and 90 means it is facing somewhere between North and East.

y angles between 270 and 360 means it is facing somewhere between West and North.
You have to assign your own thresholds if the device can freely rotate around its own y-axis
Ex: angles between 45 and 135 is considered east.