Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

New Contributor
Posts: 3
Registered: ‎09-03-2014
My Device: Q10
My Carrier: China Unicom
Accepted Solution

How to use the "sensors" api?

[ Edited ]

Hi guys! I'm a web-game developer but a newbie in blackberry app development.

I intended to creat a star atlas app and I have already finish most of it but failed to utilise the "sensors" api.

I referred to the example in the webworks 2.1 documentation as below:

function compassCallback(data) {
document.write("Current azimuth:"+data.azimuth);
blackberry.sensors.setOptions("devicecompass", { delay: 1000 });
document.addEventListener("devicecompass", compassCallback);

and I added a feature element in the config.xml: <feature id="blackberry.sensors"/>

also I added the com.blackberry.sensors plugin to the project.

But I still can't get the compass' azimuth...


I really appreciate if anybody could help me with this!

Newbie in webworks development
New Contributor
Posts: 3
Registered: ‎09-03-2014
My Device: Q10
My Carrier: China Unicom

Re: How to use the "sensors" api?

I have solved this problem by myself.

The api listener must be placed in an "deviceready" event. 


document.addEventListener('deviceready', function(e) {


This is a simple problem which might be neglected by advanced developers, because most advanced developers use "BBUI.js" and add deviceready event by default.
Hope this issue would help newbies like me...
Newbie in webworks development