pleshy
pleshy

Reputation: 1518

PhoneGap Build - Location API timeout

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

Upvotes: 2

Views: 492

Answers (1)

Dom
Dom

Reputation: 2569

Do I need to include an reference to phonegap.js in my html file?

  • Yes.

Do I need to include an empty phonegap.js in the zip folder I upload?

  • No. Phonegap build will package it in for you

Are there any other options I need to include in the config.xml to get this working?

  • No. That's it.

Upvotes: 1

Related Questions