Unable to get compass heading on Android

I’m making an Android test app (ID 169218) to get the compass heading of the device when a button is pressed.

The home screen has a paragraph component bound to the heading page variable of type number bound to the formula sensorVars.compass.latestValue.heading:

There’s also a Get heading button with a logic flow that calls Get single compass value and Set page variable heading to the formula sensorVars.compass.latestValue.heading:

When I test the app with the AppGyver app and tap Get heading, the paragraph component remains blank and no heading appears. The debugger shows the compass heading value in both the sensor variables and in the heading page variable.

What am I doing wrong? Is this a bug?

I have a Pixel 4 XL with Android 11 and version 2.4.3 of the AppGyver app. I’m in the Beta program but the test app doesn’t have the Beta option turned on.

Hi! Not entirely sure what’s going on, and I could only test this on iOS for now, but I was able to get it to work on iOS using 2.4.3 correctly.

There is no page variable setting before, but the heading: 64.71 is tied via formula to "heading: " + sensorVars.compass.latestValue.heading.

If looking at this setup you can’t get it to work for you, I’ll have a look at your app, please let me know :thinking:

Thanks, I’ll see if I can replicate your setup.

Hi Paolo,
any updates on this?

I don’t get compass responses either.
When debbuging, the compass sensor variable “active” doesn’t switch to true when clicking the Button to enable the compass, which seems odd.
The output of sensorVars.compass.latestValue.heading is either undefined or [Object object]
(used the concatenation like @Mevi "test: " + sensorVars.compass.latestValue.heading

No updates sorry, I haven’t checked it in a while.

I just made a super simple Compass viewer. I started Compass polling flow function when page loads, then I just binded this formula to a paragraph:

"HEADING: " + STRING(IF(ABS(360-sensorVars.compass.latestValue.heading.degree) < 22.5 || ABS(360-sensorVars.compass.latestValue.heading.degree) > 337.5, “North”, IF(ABS(270-sensorVars.compass.latestValue.heading.degree) < 22.5 , “West”, IF(ABS(180-sensorVars.compass.latestValue.heading.degree) < 22.5 , “South”, IF(ABS(90-sensorVars.compass.latestValue.heading.degree) < 22.5 , “East”, IF(ABS(315-sensorVars.compass.latestValue.heading.degree) < 22.5 , “North-West”, IF(ABS(45-sensorVars.compass.latestValue.heading.degree) < 22.5 , “North-East”, IF(ABS(135-sensorVars.compass.latestValue.heading.degree) < 22.5 , “South-East”, IF(ABS(225-sensorVars.compass.latestValue.heading.degree) < 22.5 , “South-West”, STRING(sensorVars.compass.latestValue.heading.degree))))))))))

It worked on my Android

2 Likes

I think the problem You all are running into is that sensorVars.compass.latestValue.heading is an Object. You need to add the .degree field to get the actual degree value.

2 Likes

Thanks - now the “object” string in the response makes sense - however, I think the documentation is misleading, it says The direction in which the device is facing, in degrees from true north.