Cordova Compass API提供了错误代码3 [英] Cordova Compass API is giving error code 3
问题描述
已经在stackoverflow 上提出了此问题.这里,但是我没有找到任何答案,所以我再次提出了这个问题.请有人能对此进行回复吗?
This question is already asked on stackoverflow here but I didn't found any answer to it, so I raised again this. Please can anyone able reply for this?
我的代码如下:
<!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">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
navigator.compass.getCurrentHeading(onSuccess, onError);
}
function onSuccess(heading)
{
alert('Heading: ' + heading.magneticHeading);
}
function onError(compassError)
{
alert('Compass Error: ' + compassError.code);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>getCurrentHeading</p>
</body>
</html>
推荐答案
您的设备没有磁传感器,或者供应商未在操作系统中实现对它的支持.
Either your device does not have a magnetic sensor, or the vendor has not implemented support for it in the OS.
查看面向设备的插件的Android源代码,启动代码是这样编写的(为简洁起见进行了修改):
Looking at the Android source code for the device-orientation plugin, the startup code is written like this (modified for brevity):
List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
// If found, then register as listener
if (list != null)
this.setStatus(CompassListener.STARTING);
// If error, then set status to error
else
this.setStatus(CompassListener.ERROR_FAILED_TO_START);
不知道为什么要在这里编写自己的错误代码( public static int ERROR_FAILED_TO_START = 3
),但实际上,他们应该按照文档中的定义报告 COMPASS_NOT_SUPPORTED
.
Not sure why they made up their own error code there (public static int ERROR_FAILED_TO_START = 3
), but really they should be reporting COMPASS_NOT_SUPPORTED
as defined in the documentation.
这篇关于Cordova Compass API提供了错误代码3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!