1、插件名
cordova-plugin-device-orientation
2、插件方法
navigator.compass.getCurrentHeading
navigator.compass.watchHeading
navigator.compass.clearWatch
3、调用方法
function onSuccess(heading) {
alert("Heading: " + heading.magneticHeading);
}
function onError(error) {
alert("CompassError: " + error.code);
}
navigator.compass.getCurrentHeading(onSuccess, onError);
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
};
function onError(compassError) {
alert('Compass error: ' + compassError.code);
};
var options = {
frequency: 3000
}; // Update every 3 seconds
var watchID = navigator.compass.watchHeading(onSuccess, onError, options);
var watchID = navigator.compass.watchHeading(onSuccess, onError, options);
// ... later on ...
navigator.compass.clearWatch(watchID);