Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
testing altitude
  • Loading branch information
Joel Salisbury committed Jan 21, 2016
1 parent 80a26e8 commit 0ce9d77
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions js/main.js
@@ -1,24 +1,39 @@
if (window.DeviceMotionEvent) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
} else {
document.getElementById("warning").innerHTML = "Not supported."
}
// if (window.DeviceMotionEvent) {
// window.addEventListener('devicemotion', deviceMotionHandler, false);
// } else {
// document.getElementById("warning").innerHTML = "Not supported."
// }


function deviceMotionHandler(eventData) {
// Grab the acceleration from the results
var acceleration = eventData.acceleration;
var trimmedaccel = acceleration.x.toPrecision(2)
// function deviceMotionHandler(eventData) {
// // Grab the acceleration from the results
// var acceleration = eventData.acceleration;
// var trimmedaccel = acceleration.x.toPrecision(2)

switch (trimmedaccel >= 0) {
case true:
$("body").addClass('up');
$("body").removeClass('down');
break;
case false:
$("body").addClass('down');
$("body").removeClass('up');
break;
}
// switch (trimmedaccel >= 0) {
// case true:
// $("body").addClass('up');
// $("body").removeClass('down');
// break;
// case false:
// $("body").addClass('down');
// $("body").removeClass('up');
// break;
// }

// }


var x = document.getElementById("warning");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude +
"<br>Altitude: " + position.coords.altitude;
}

0 comments on commit 0ce9d77

Please sign in to comment.