Function Accelerometre

Par RaphBellahsen, il y a 11 ans


Bonjour a tous ,

Je fais face a un probleme dans mon code sous cordova : je n'arrive pas a afficher les donnes x,y z de l'accelerometre.

Un code ou je bloque :

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <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" /> <style> body { margin: 0px; } #footerTable { width: 100%; } footer { position:absolute; bottom:0; width:100%; height:40px; background:#ccc; } </style> <script type="text/javascript" src="cordova.js"></script> <script> var watch = 0; window.onload = function() { //init(); document.addEventListener("deviceready", init, false); alert("Onload Verifie"); } function init() { alert("Init Verifie"); watch = navigator.accelerometer.watchAcceleration(success, failure, {frequency: 100}); } function success(accel) { alert("Test Verifie"); document.getElementById("xOut").innerHTML = accel.x; document.getElementById("yOut").innerHTML = accel.y; document.getElementById("zOut").innerHTML = accel.z; } function failure() { alert("Error"); } </script> <title>Pedometer</title> </head> <body> <footer> <table id="footerTable"> <tr> <td>X: <span id="xOut">NA</span></td> <td>Y: <span id="yOut">NA</span></td> <td>Z: <span id="zOut">NA</span></td> </tr> </table> </footer> </body> </html>

Voila les deux premier alert s'affiche sauf le dernier ce qui pose probleme a l'affichage des valeurs.
Merci et a bientot :)

2 réponses

TransientDev, il y a 11 ans

Bonjour,
ne serait-ce pas plutôt

watch = navigator.accelerometer.watchAcceleration(success(), failure(), {frequency: 100});
RaphBellahsen, il y a 11 ans

non en fait mon code marchait le pb venait de l'emulateur mais merci quand meme