cordova插件-Device Orientation

时间:2022-05-06
本文章向大家介绍cordova插件-Device Orientation,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
  • 添加插件

$ cordova plugin addcordova-plugin-device-orientation

图 13如上则插入成功

  • 插件的使用
  • Methods
  • navigator.compass.getCurrentHeading
  • navigator.compass.watchHeading
  • navigator.compass.clearWatch

2. Example

    var watchID;
    function getCurrent () {

        navigator.compass.getCurrentHeading(onSuccess, onError);
    }

    function onSuccess(heading) {
        alert('Heading: ' + heading.magneticHeading);
    };

    function onError(error) {
        alert('CompassError: ' + error.code);
    };

////////////////////////////////////////////////////////////////////////////

    function watchH() {
        var options = {
            frequency: 3000
        }; // Update every 3 seconds

         watchID = navigator.compass.watchHeading(onSuccess, onError, options);
    }


    ///////////////////////////////////////////////////////////////////////

    function clearW() {

        navigator.compass.clearWatch(watchID);
    }