apache / cordova-plugin-device-orientation

Apache Cordova Device Orientation Plugin
https://cordova.apache.org/
Apache License 2.0
58 stars 83 forks source link

Horizontal compass heading not working #51

Open KeySeeDev opened 5 years ago

KeySeeDev commented 5 years ago

Hi, i've been using this plugin to get the absolute north point. There is some problem with it. When using navigator.compass.getCurrentHeading(console.log); If the phone is in portrait mode there is no problem...the value goes from 0 to 359.99 But when the phone is in landscape mode the values are totally wrong and not stable at all, varying almost +/-20 degrees... Soo, how to get the right value?

Orientation  | Degrees | Degrees |
----------------------------------
Portrait     |     0   |    45   |
Landscape    |    20   |    80   |
UpsideDown   |   160   |   220   |
Landscape    |   190   |   350   |
KeySeeDev commented 5 years ago

I'm not an Android developer but i think that it could be fixed by implementing SensorManager.remapCoordinateSystem I will try my best to fix it.

KeySeeDev commented 5 years ago

Yep, it works. Gotta add the device orietation check to use the right axis while remapping.

lukepighetti commented 4 years ago

@StarStep what is the current status of this bug? I've been looking across cordova/xamarin/react native packages for an implementation on Android that works in landscape mode and I have yet to find one.

KeySeeDev commented 4 years ago

I'm working on another project... sorry. I dont know if it was fixed. You could try to test it and confirm for yourself better. My test code was something like this:

function show(text) { document.body.innerHTML = text; }

function updatePosition() {
    navigator.compass.getCurrentHeading(function(heading) {
        show(JSON.stringify(heading, null, 2));
    }, function() {
        show("Heading not available");
    });
}

setInterval(updatePosition, 1000);
HiveTechDev commented 3 years ago

Has there been any progress on this? i have an application that we'd like to get compass directions for both landscape and portrait.

davidpadych commented 3 years ago

I had the same problem ... then the deviation was caused by the magnetic case of the tablet