I'm unable to get the value from Accelerometer on Ionic Framework and here is the code below,
Executing the code get an error :
Cannot read property 'getCurrentAcceleration' of undefined
.controller('DashCtrl', function($cordovaDeviceMotion) {
$cordovaDeviceMotion.getCurrentAcceleration().then(function(result) {
var X = result.x;
var Y = result.y;
var Z = result.z;
var timeStamp = result.timestamp;
console.log(result);
}, function(err) {
console.log(err);
// An error occurred. Show a message to the user
});
// watch Acceleration
var options = { frequency: 20000 };
var watch = $cordovaDeviceMotion.watchAcceleration(options);
watch.then(
null,
function(error) {
// An error occurred
},
function(result) {
var X = result.x;
var Y = result.y;
var Z = result.z;
var timeStamp = result.timestamp;
});
watch.clearWatch();
// OR
$cordovaDeviceMotion.clearWatch(watch)
.then(function(result) {
console.log(result);
// success
}, function (error) {
// error
});
})
More Info :
$cordovaDeviceMotion
, I am getting empty{} object$cordovaDeviceMotion is not working on the browser but working on my android deceive. we can't able to test on browser.
ngCordova : Right now the device motion not working on browser but working in device(App) Apache Cordova : Working on both browser and app.
So, I raised the issue on GitHub