4

I am developing a phonegap app targeting iOS platform. I want to capture user's geo location. I am using below code for this which worked fine for sometime and suddenly stopped working

    <script type="text/javascript">

    var onSuccess = function(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');
     }

    navigator.geolocation.getCurrentPosition(onSuccess, onError);

    </script>

Above code returned latitude and longitude for approx 7 times but after that success callback function is not being called and sometimes it shows user denied popup on browser.

user3034998
  • 123
  • 2
  • 9

1 Answers1

0

you can try these options :

{timeout: 30000, enableHighAccuracy: true, maximumAge: 75000}

//navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 30000, enableHighAccuracy: true, maximumAge: 75000});

enableHighAccuracy – A boolean (true/false) which indicates to the device that you wish to obtain it’s most accurate readings (this parameter may or may not make a difference, depending on your hardware)

maximumAge – The maximum age (in milliseconds) of the reading (this is appropriate as the device may cache readings to save power and/or bandwidth)

timeout – The maximum time (in milliseconds) for which you are prepared to allow the device to try to obtain a Geo location

radia
  • 1,456
  • 1
  • 13
  • 18
  • Today it is working fine but only on simulator, when i run it on actual iOS device it worked once then stopped – user3034998 Apr 10 '14 at 09:42
  • Device can cache geoloc values to save power, this solution helps you force information update. Have you tried at least? you can set the values you need i'm just givind an example – radia Apr 10 '14 at 09:51