Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |