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?