works differently

This commit is contained in:
moorgar11 2014-03-18 08:30:57 +01:00
parent 40072c503b
commit 56633995db
3 changed files with 30 additions and 8 deletions

View file

@ -26,6 +26,7 @@
<preference name="orientation" value="portrait" /> <preference name="orientation" value="portrait" />
<gap:plugin name="org.apache.cordova.device-orientation" /> <gap:plugin name="org.apache.cordova.device-orientation" />
<gap:plugin name="org.apache.cordova.device-motion" />
<feature name="Compass"> <feature name="Compass">
<param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" /> <param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />

17
main.js
View file

@ -1,19 +1,20 @@
var onSuccess = function(heading) { function onSuccess(acceleration) {
var element = document.getElementById('heading'); alert('Acceleration X: ' + acceleration.x + '\n' +
element.innerHTML = 'Heading: ' + heading.magneticHeading; 'Acceleration Y: ' + acceleration.y + '\n' +
drawDial(heading.magneticHeading*Math.PI/180); 'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}; };
var onErrors = function() { function onError() {
alert('Compass error: ' + compassError.code); alert('onError!');
}; };
var startup = function(){ var startup = function(){
watchID = navigator.compass.watchHeading(onSuccess, onErrors, options); watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError);
lockinit(); lockinit();
} }
var watchID = null;
var options = { frequency: 1000 }; var options = { frequency: 1000 };
document.addEventListener("deviceready", startup, false); document.addEventListener("deviceready", startup, false);

20
main2.js Normal file
View file

@ -0,0 +1,20 @@
var onSuccess = function(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
drawDial(parseInt(heading.magneticHeading)*Math.PI/180);
};
var onErrors = function() {
alert('Compass error: ' + compassError.code);
};
var startup = function(){
watchID = navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);
lockinit();
}
var watchID = null;
var options = { frequency: 1000 };
//window.onload = lockinit;
document.addEventListener("deviceready", startup, false);