Hey there,
since i’ve tried to accomplish this with ng-cordovas deviceorientation and it didn’t worked, I switched over to HTML5…
so here’s the thing…
if I’m using this > http://www.html5rocks.com/en/tutorials/device/orientation/
I only get positiv values so I can’t really detect wether am tilting to the left or right.
So my image is always rotating to 1 side.
Here’s my controller.
.controller('DiagWinkelACtrl', function($scope,$state,$rootScope) {
$rootScope.deviceOrientationHandler = function(tiltLR, tiltFB, dir) {
$scope.iDeg = Math.round(tiltFB);
$scope.$apply(function () {
$scope.myDeg = $scope.iDeg + '°';
});
if($scope.iDeg > 0) {
$scope.ekDeg = 90 - $scope.iDeg;
}
else {
$scope.ekDeg = 90 + $scope.iDeg;
}
$("img#daDreh").css('transform', 'rotate('+ $scope.ekDeg +'deg)').css('transition', '300ms linear all');
};
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// compass
var dir = eventData.alpha;
// call our orientation event handler
$rootScope.deviceOrientationHandler(tiltLR, tiltFB, dir);
}, false);
};
})
this obv. doesn’t work because $scope.iDeg is always positive … any idea how I can do this?