Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Cordova compass API(navigator.compass.watchHeading)不工作(错误代码3)_Javascript_Android_Cordova_Cordova Plugins_Compass - Fatal编程技术网

Javascript Cordova compass API(navigator.compass.watchHeading)不工作(错误代码3)

Javascript Cordova compass API(navigator.compass.watchHeading)不工作(错误代码3),javascript,android,cordova,cordova-plugins,compass,Javascript,Android,Cordova,Cordova Plugins,Compass,我试图使用cordova compass运行一个示例应用程序,但每次调用错误回调时都会出现错误代码3 我使用cordova V4.0,当然我添加了插件org.apache.cordova.device-orientation。代码如下: 罗盘示例 //watch id引用当前的“watchHeading”` var gWatchID=null; //等待加载设备API库 文件。添加的监听器(“deviceready”,OnDeviceraddy,false); //设备API可用 函数ond

我试图使用cordova compass运行一个示例应用程序,但每次调用错误回调时都会出现错误代码3

我使用cordova V4.0,当然我添加了插件org.apache.cordova.device-orientation。代码如下:


罗盘示例
//watch id引用当前的“watchHeading”`
var gWatchID=null;
//等待加载设备API库
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//设备API可用
函数ondevicerady(){
startWatch();
}
//开始观察指南针
函数startWatch(){
//每3秒更新一次罗盘
var选项={频率:3000};
如果(!gWatchID)
gWatchID=navigator.compass.watchHeading(onSuccess、onError、options);
}
//别看罗盘了
功能秒表(){
if(gWatchID){
navigator.compass.clearWatch(watchID);
gWatchID=null;
}
}
//onSuccess:获取当前标题
功能成功(标题){
var元素=document.getElementById('heading');
element.innerHTML='Heading:'+Heading.magneticeReading;
}
//OneError:无法获取标题
函数onError(compassError){
警报(“指南针错误:”+指南针错误代码);
}
等待航向。。。
开始看
别看了

您的设备没有磁性传感器,或者供应商没有在操作系统中对其实施支持

查看设备定向插件的Android源代码,启动代码是这样编写的(为简洁起见进行了修改):

List List=this.sensorManager.getSensorList(Sensor.TYPE_方向);
//如果找到,则注册为侦听器
如果(列表!=null)
this.setStatus(CompassListener.STARTING);
//如果出现错误,则将状态设置为错误
其他的
this.setStatus(CompassListener.ERROR\u启动失败);

不确定他们为什么在那里编写自己的错误代码(
public static int error\u FAILED\u TO\u START=3
),但实际上他们应该报告文档中定义的
COMPASS\u不受支持

真的吗?没人能帮上忙吗?我真的是唯一一个想使用cordova插件的人吗???
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);