如何使用计步器插件? [英] How to use the pedometer plugin?

查看:80
本文介绍了如何使用计步器插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于本机应用程序的projet.我必须在Cordova中编写一个简单的计步器.我已将插件下载到文件中,但无法成功获取所有信息 这是我的代码:

i'm a working on a projet based on native application. I have to code a simple pedometer in cordova. I've downloaded the plugin in my file and i don't succed to get all the informations back Here is my code :

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Pedometer</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script>
        var successHandler = function (pedometerData) {
    // pedometerData.numberOfSteps;
    // pedometerData.distance;
    // pedometerData.floorsAscended;
    // pedometerData.floorsDescended;
};
         pedometer.startPedometerUpdates(successHandler, onError);
 
         pedometer.stopPedometerUpdates(successCallback, failureCallback);
 
 
 
 
        </script>
    </body>
</html>

感谢您的帮助! ;)

推荐答案

根据

平台和设备支持

仅iOS 8+.并非所有设备都支持这些功能,甚至 在iOS 8上,因此请确保您使用检查功能支持 功能.

iOS 8+ only. These capabilities are not supported on all devices, even with iOS 8, so please ensure you use the check feature support functions.

因此,您可以测试此代码是否支持该功能:

So, you can test if the feature is supported with this code:

pedometer.isStepCountingAvailable(function(){
    console.log( "Pedometer step counting is available" );
}, function(){
    console.log( "Pedometer step counting is NOT available" );
});

然后您可以对pedometer.isDistanceAvailable()pedometer.isFloorCountingAvailable

这篇关于如何使用计步器插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆