2

this question seems to be have asked quite a few times but I cannot seem to fix the problem.

Basically all I want to do is get the lat/lng of user, I am using phonegap build version 2.9. The device I am testing on is an android HTC One X, with WiFi enabled and GPS.

In my code I have the following:

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>

response I get

I know my GPS is working because Google Maps APP works fine

onError() is always called

Error Code 3 Timeout

I have also seen a similar question asked before, but this did not solve the problem. phonegap geolocation allways fail on timeout

I have a couple of questions which might help me fix this

  • Do I need to include an reference to phonegap.js in my html file?
  • Do I need to include an empty phonegap.js in the zip folder I upload?
  • Are there any other options I need to include in the config.xml to get this working?
4

1 回答 1

1

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

  • 是的。

我是否需要在上传的 zip 文件夹中包含一个空的 phonegap.js?

  • 不会。Phonegap build 会为您打包

我需要在 config.xml 中包含任何其他选项以使其正常工作吗?

  • 不,就是这样。
于 2013-09-06T12:06:21.660 回答