If the compass of the Sony Xperia XZ3 does not work properly anymore, this is usually due to an incorrect calibration of the magnetic sensor.
This can happen over time, as the magnetic sensor is influenced by electromagnetic external influences. The magnetic sensor or compass can be calibrated on the Sony Xperia XZ3 as follows:
Compass Calibration - Instructions
1. Please open the previously installed Compass App on the Sony Xperia XZ3.
2. Swivels the smartphone in front of you in the shape of a lying "8"
3. Then turns the Sony Xperia XZ3 completely around each of its three axes once.
Afterwards the calibration should be finished and the compass should show the correct direction.
If this is not the case, please repeat the above two steps on your Sony Xperia XZ3.
Now the compass app on the Sony Xperia XZ3 should show the right direction again and show you the right direction in Google Maps for example.