Hi, I’m trying to get the function navigator.accelerometer working.
I saw there was an article posted on Wed Aug 28, 2013 but unfortunately I couldn’t get this to work. Whenever I inspect the code for navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);, the system says “Uncaught TypeError: Cannot call method ‘getCurrentAcceleration’ of undefined”.
Should I be including an extra javascript file?
I’ve also tried
watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
but get the same problem.
The sample code is:
// Start watching the acceleration //
function startWatch()
{
watchID = navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration)
{
var element = document.getElementById(‘m1-MobiOne-OutputStatus’);
element.innerHTML = ‘Acceleration X: ‘ + acceleration.x + ‘<br />’ + ‘Acceleration Y: ‘ + acceleration.y + ‘<br />’ + ‘Acceleration Z: ‘ + acceleration.z + ‘<br />’ +
‘Timestamp: ‘ + acceleration.timestamp + ‘<br />’;
}
// onError: Failed to get the acceleration
//
function onError()
{
alert(‘onError – acceleration!’);
}