Adding a compass field to an application

The net.rim.device.api.lbs.compass.CompassField class allows you to add a visual representation of a compass rose to your application, without requiring that you implement the Magnetometer APIs. CompassField objects can be created and added to a field manager, just like any other UI component. After you add a CompassField object to a screen, the field listens to the magnetometer sensor for changes to the bearing of the BlackBerry device, and re-renders the field accordingly.

Since the compass field relies on the magnetometer sensor to function correctly, the device might need to be calibrated occasionally so that the compass field displays an accurate heading (such as when the device comes in contact with a magnetic field). When device calibration is required, a prompt appears that instructs the user to calibrate the device. The calibration prompt generated by the CompassField class is the same as the prompt generated by the Compass application.

Once the compass field is no longer required, you must close it to ensure that your application releases the resources that are associated with it.

Adding a compass field to a screen

CompassField compField = new CompassField();
addItem(compField);

Releasing a compass field's resources

compField.close();

Was this information helpful? Send us your comments.