首先我想说,我看到了很多类似的问题,其中许多人只是说需要在
因此,我已经测试和修复了我的代码一段时间,但仍然从
所以这里是来自URL的干净代码:
在我的config.xml文件中,我已经添加了以下内容:
<script src="cordova-x-x-x.js"></script>
中添加cordova.js文件,而有些则不需要在Phonegap Build中包含该文件。因此,我已经测试和修复了我的代码一段时间,但仍然从
onError function
中得到错误。我还从phonegap文档中复制并粘贴了代码。所以这里是来自URL的干净代码:
<!DOCTYPE html>
<html>
<head>
<title>Acceleration 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.accelerometer.getCurrentAcceleration(onSuccess, onError);
}
function onSuccess(acceleration) {
alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}
function onError() {
alert('onError!');
}
</script>
</head>
<body>
</body>
</html>
在我的config.xml文件中,我已经添加了以下内容:
<gap:plugin name="org.apache.cordova.device-motion" />
<gap:plugin name="org.apache.cordova.device-orientation" />