【发布时间】:2013-08-07 20:00:57
【问题描述】:
对于智能手机的增强现实网络应用,我试图在用户手持设备、屏幕处于垂直平面且屏幕顶部朝上时计算指南针航向。
我从http://dev.w3.org/geo/api/spec-source-orientation(参见工作示例)中获取了建议的公式并实现了以下功能:
function compassHeading(alpha, beta, gamma) {
var a1, a2, b1, b2;
if ( beta !== 0 || gamma !== 0 ) {
a1 = -Math.cos(alpha) * Math.sin(gamma);
a2 = Math.sin(alpha) * Math.sin(beta) * Math.cos(gamma);
b1 = -Math.sin(alpha) * Math.sin(gamma);
b2 = Math.cos(alpha) * Math.sin(beta) * Math.cos(gamma);
return Math.atan((a1 - a2) / (b1 + b2)).toDeg();
}
else {
return 0;
}
}
而 .toDeg() 是 Number 对象扩展,礼貌http://www.movable-type.co.uk/scripts/latlong.html
/** Converts radians to numeric (signed) degrees */
if (typeof Number.prototype.toDeg == 'undefined') {
Number.prototype.toDeg = function() {
return this * 180 / Math.PI;
};
}
但是,问题在于,即使将设备 (Google Galaxy Nexus) 安装为保持静止位置,计算出的罗盘航向值也会从大约 -75 跳到 80。这似乎发生在 Google Chrome BETA 和 FF BETA 23 中。
是否有人发现我的方法有错误或知道计算指南针航向的更可靠方法?
【问题讨论】:
标签: html google-chrome firefox math