2016-08-05 18:09:50 -04:00
|
|
|
"use strict";
|
|
|
|
|
2016-08-05 21:17:32 -04:00
|
|
|
let gPosition = null;
|
|
|
|
let gOrientation = null;
|
|
|
|
let gError = null;
|
|
|
|
|
|
|
|
function draw() {
|
2016-08-05 18:09:50 -04:00
|
|
|
terminal.cork();
|
2016-08-05 21:17:32 -04:00
|
|
|
terminal.clear();
|
|
|
|
if (gPosition) {
|
|
|
|
for (let field in gPosition.coords) {
|
|
|
|
let value = gPosition.coords[field];
|
2016-08-05 18:09:50 -04:00
|
|
|
terminal.print(field, ": ", value != null ? value.toString() : "null");
|
|
|
|
}
|
2016-08-05 21:17:32 -04:00
|
|
|
}
|
|
|
|
if (gOrientation && gOrientation.alpha && gOrientation.beta && gOrientation.gamma) {
|
|
|
|
terminal.print(gOrientation.alpha.toString(), ", ", gOrientation.beta.toString(), ", ", gOrientation.gamma.toString(), ", ", gOrientation.absolute.toString());
|
|
|
|
}
|
|
|
|
if (gError) {
|
2016-08-05 18:09:50 -04:00
|
|
|
terminal.print(event.error.message);
|
|
|
|
terminal.clearWatch();
|
|
|
|
}
|
|
|
|
terminal.uncork();
|
2016-08-05 21:17:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
core.register("geolocation", function(event) {
|
|
|
|
if (event.position) {
|
|
|
|
gPosition = event.position;
|
|
|
|
} else if (event.error) {
|
|
|
|
gError = event.error;
|
|
|
|
}
|
|
|
|
draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
core.register("deviceorientation", function(event) {
|
|
|
|
gOrientation = event.orientation;
|
|
|
|
draw();
|
2016-08-05 18:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
terminal.watchPosition({enableHighAccuracy: true});
|
2016-08-05 21:17:32 -04:00
|
|
|
terminal.setSendDeviceOrientationEvents(true);
|