我正在尝试使用 cordova 指南针运行示例应用程序,但每次使用错误代码 3 调用错误回调。
我使用cordova V4.0,当然我添加了插件org.apache.cordova.device-orientation。这是代码:
<!DOCTYPE html>
<html>
<head>
<title>Compass Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// The watch id references the current `watchHeading`
var gWatchID = null;
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
function onDeviceReady() {
startWatch();
}
// Start watching the compass
function startWatch() {
// Update compass every 3 seconds
var options = { frequency: 3000 };
if (!gWatchID)
gWatchID = navigator.compass.watchHeading(onSuccess, onError, options);
}
// Stop watching the compass
function stopWatch() {
if (gWatchID) {
navigator.compass.clearWatch(watchID);
gWatchID = null;
}
}
// onSuccess: Get the current heading
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
}
// onError: Failed to get the heading
function onError(compassError) {
alert('Compass error: ' + compassError.code);
}
</script>
</head>
<body>
<div id="heading">Waiting for heading...</div>
<button onclick="startWatch();">Start Watching</button>
<button onclick="stopWatch();">Stop Watching</button>
</body>
</html>
该应用程序已成功构建、部署和启动。但是当它启动时,只显示错误代码3。
根据文档,仅定义了两个错误代码: CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20;
所以我想知道错误代码3是什么意思?我做错了什么?
谢谢你的回答,但丁