我正在iPhone 5s上运行一个three.js phonegap项目,该项目根据罗盘标题读数旋转摄像机。所有工作都应该如此,但是在10秒后冻结罗盘读数。该应用程序继续正常工作,但不再调用函数 rotateCameraWithCompass 。此外,没有调用 compassError 。 watchHeading 方法似乎已冻结。
30毫秒的频率似乎是现实的,或者这在技术上是否超出界限
更新:我将频率降低到100毫秒,大约10秒后仍然冻结。
function rotateCameraWithCompass( heading ) {
camera.rotation.y = -1 * Math.toRad( heading.magneticHeading );
}
function compassError( compassError ) { console.log( 'Compass error: ' + compassError.code ); }
var watchID = navigator.compass.watchHeading( rotateCameraWithCompass, compassError, { frequency: 30 } );
答案 0 :(得分:0)
Answer posted to Google Groups:
https://groups.google.com/forum/#!topic/phonegap/OEZO1-0LMT4
Read the docs Luke!
iOS has quirks noted in the documentation:
Only one watchHeading can be in effect at one time in iOS. If a watchHeading uses a filter, calling getCurrentHeading or watchHeading uses the existing filter value to specify heading changes. Watching heading changes with a filter is more efficient than with time intervals.
http://docs.phonegap.com/en/4.0.0/cordova_plugins_pluginapis.md.html#Plugin%20APIs
http://plugins.cordova.io/#/package/org.apache.cordova.device-orientation
Bottom line: Use the filter as described by Jan