1 Reply Latest reply on May 2, 2017 11:25 AM by surajpindoria

    navigator.geolocation.getCurrentPosition fails when offline

    sethup51656429 Level 1

      var onSuccess = function (position) {

          $('#flocation').val((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3))

          localStorage.currentLocation = (position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3);

          //alert((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3))

          $('#slocation').html((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3))

       

       

          $('#location').val((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3));

          $('#nlocation').value((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3));

        

      };

       

       

      function onError(error) {

          console.log('code: ' + error.code + '\n' +

                  'message: ' + error.message + '\n');

      }

       

       

      document.addEventListener("deviceready", onDeviceReady, false);

       

       

      setInterval(function(){

         

           navigator.geolocation.getCurrentPosition(onSuccess1, onError);

      },1)

        

       

       

       

       

      function onSuccess1(position)

      {

          $('#flocation').val((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3))

          $('#slocation').html((position.coords.latitude).toFixed(3) + "," + (position.coords.longitude).toFixed(3))

         

      }

      function onDeviceReady() {

       

       

       

       

          if (window.cordova) {

       

       

              cordova.plugins.diagnostic.isGpsLocationEnabled(

                      function (e) {

                          if (e) {

                              navigator.geolocation.getCurrentPosition(onSuccess, onError);

       

       

                          } else {

                             

                              alert("Location Not Turned ON");

                              cordova.plugins.diagnostic.switchToLocationSettings();

                          }

                      },

                      function (e) {

                          console.log('Error ' + e);

                      }

              );

          }

      }

       

       

       

      This is my code.When  the user is Online i get the location co-ordinate quickly..But when offline no location is fetching and also no error messages showing .i'm using

      <plugin name="cordova-plugin-geolocation" spec="~2.1.0" />

       

      plugin for geting location...

      Can you help me?