2

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>

Thanks for your help ! ;)

Raphael00
  • 61
  • 1
  • 9

1 Answers1

0

According to the docs:

Platform and device support

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" );
});

and then you can do the same thing with pedometer.isDistanceAvailable() and pedometer.isFloorCountingAvailable

blurfus
  • 13,485
  • 8
  • 55
  • 61
  • but it said connection to device when i launch ripple :/ – Raphael00 Feb 24 '15 at 21:41
  • it says 'connecting to device' and 'device ready' in your HTML but it is not bound to a pedometer. It changes when the (mobile) device is has loaded the DOM (i.e. in 'ready' state) – blurfus Feb 24 '15 at 21:47
  • but when i click on the index.html , the function document.addEventListener('deviceready', this.onDeviceReady, false); }, must turn on True right ? – Raphael00 Feb 24 '15 at 22:21
  • I see no evidence of that. What makes you believe so? According to the docs (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) if you use `false`, you are not indicating you want `userCapture`. Perhaps you meant to put `true`? – blurfus Feb 24 '15 at 22:39