cordova-plugin-device-orientation icon indicating copy to clipboard operation
cordova-plugin-device-orientation copied to clipboard

Horizontal compass heading not working

Open KeySeeDev opened this issue 6 years ago • 6 comments

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 avatar Feb 03 '19 17:02 KeySeeDev

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 avatar Feb 04 '19 11:02 KeySeeDev

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

KeySeeDev avatar Feb 04 '19 13:02 KeySeeDev

@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.

lukepighetti avatar Sep 28 '20 12:09 lukepighetti

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);

KeySeeDev avatar Sep 29 '20 21:09 KeySeeDev

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

HiveTechDev avatar Feb 06 '21 01:02 HiveTechDev

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

davidpadych avatar Jun 15 '21 14:06 davidpadych