如何使用计步器插件
How to use the pedometer plugin?
我正在开发一个基于本机应用程序的项目。我必须用科多瓦编码一个简单的计步器。我已经在我的文件中下载了插件,但我没有成功地获得所有信息这是我的代码:
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,因此请确保使用检查功能支持功能。
因此,您可以用以下代码测试该功能是否受支持:
pedometer.isStepCountingAvailable(function(){
console.log( "Pedometer step counting is available" );
}, function(){
console.log( "Pedometer step counting is NOT available" );
});
然后可以对pedometer.isDistanceAvailable()
和pedometer.isFloorCountingAvailable
执行相同的操作
相关文章:
- 如何在elfinder插件(一个文件管理器插件)上获得上传前事件
- jQuery滚动器插件修改
- firefox插件:退出不工作的应用程序观察器
- 用于 Eclipse 的 JavaScript 编辑器插件
- Jquery-如何获取插件调用的选择器
- 周/年选择器jQuery插件
- 函数比javascript中的步进器增加/减少更多
- 如果使用jQuery验证器插件找到单选按钮,则将不同的addMethod应用于字段
- 在Firefox插件中注册控制台服务侦听器
- 如何制作一个具有多个选择器的jQuery插件,在每个选择器上分别进行匹配
- Jquery循环洗涤器插件:添加到图像的链接
- 如何在 elfinder(一个 jquery 文件管理器插件)中只显示文件夹列表
- CSS + jQ插件阻止AJAX调用/事件侦听器工作
- 如何使用计步器插件
- 数据插件选项筛选器不工作
- 如何只获取当天的总步数(计步器)(S2档)
- 如何为wordpress创建一个自定义(不使用插件)新闻阅读器
- 有关于Tizen Web应用程序模板的文档吗?(如媒体控制器,相机,计步器)
- GRAYT插件在编辑器中破坏HTML
- Jquery插件:从调用器中提取数据