2013-07-08 48 views
2

这个问题似乎已经问了好几遍,但我似乎无法解决这个问题。PhoneGap Build - 位置API超时

基本上我想要做的就是获取用户的纬度/经度,我使用phonegap build版本2.9。我正在测试的设备是安卓HTC One X,具备WiFi和GPS功能。

在我的代码,我有以下:

config.xml中

<feature name="http://api.phonegap.com/1.0/device"/> 
<feature name="http://api.phonegap.com/1.0/geolocation"/> 

的index.html

<script type="text/javascript"> 
// Wait for Cordova to load 
document.addEventListener("deviceready", onDeviceReady, false); 

// wait for phonegap to be ready 
function onDeviceReady() { 
    navigator.geolocation.getCurrentPosition(onSuccess, onError, { maximumAge: 3000, timeout: 10000, enableHighAccuracy: false }); 
} 

// onSuccess Geolocation 
function onSuccess(position) { 
    alert( 
     'Latitude: '   + position.coords.latitude    + "\n" + 
     'Longitude: '   + position.coords.longitude    + "\n" + 
     'Altitude: '   + position.coords.altitude    + "\n" + 
     'Accuracy: '   + position.coords.accuracy    + "\n" + 
     'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + "\n" + 
     'Heading: '   + position.coords.heading    + "\n" + 
     'Speed: '    + position.coords.speed     + "\n" + 
     'Timestamp: '   + position.timestamp     + "\n" 
     ); 
} 

// onError Callback receives a PositionError object 
function onError(error) { 
    alert(
     'code: ' + error.code + '\n' + 
     'message: ' + error.message + '\n' 
    ); 
} 
</script> 

响应我得到

我知道我的GPS工作,因为谷歌地图应用工作正常

的onError()总是叫

错误代码3 超时

我也看到之前问过类似的问题,但这并没有解决问题。 phonegap geolocation allways fail on timeout

我有一对夫妇的这可能帮助我解决这个

  • 问题我需要在我的html文件phonegap.js的参考?
  • 我需要在我上传的zip文件夹中包含一个空的phonegap.js吗?
  • 我需要在config.xml中包含任何其他选项才能使其正常工作吗?
+0

我开始认为这是一个HTC One X问题。我也找不到答案。适用于我尝试过的所有其他设备。 – KickingLettuce

回答

1

我需要在html文件中包含对phonegap.js的引用吗?

  • 是的。

我需要包含在ZIP文件夹我上传一个空phonegap.js?

  • 号的PhoneGap构建将其打包为你

是否有任何其他选项,我需要在config.xml包括获得 这方面的工作?

  • 不,就是这样。