I'm working on my first cordova project and I'm testing on an emulator.
I need to use navigator.geolocation to get the coordinates.
I have installed the cordova geolocation plugin and it's also mentioned in the config.xml file. I've given location access to the app in the emulator settings and I also click the "send" button in the the emulator's extended settings.
Despite this, the geolocation keeps failing and I don't know why.
Here is the js code:
//Initialise entry page for the first time and handle entry page input validation
$(document).delegate("#entry_page","pageinit",function()
{
  if (navigator.geolocation)
  {
    navigator.geolocation.getCurrentPosition(onSuccess, onError, {timeout: 30000});
  }
  //rest of code
    if(latitude == null || longitude == null)
    {
      alert("Location not given. Please allow location access and refresh the application");
      error_free = 0;
    }
    if(dateTime == null)
    {
      alert("Date & Time not acquired");
      error_free = 0;
    }
    // remaining code
    });
  });
  //Get location and time values on successful location access
  function onSuccess(position)
  {
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
    today = new Date();
    date = today.getDate()+'/'+(today.getMonth()+1)+'/'+today.getFullYear();
    time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    dateTime = date+' '+time;
  }
  //Throw error if location access is not possible
  function onError(error) {
    var txt;
    switch(error.code)
    {
      case error.PERMISSION_DENIED:
      txt = 'Location permission denied';
      break;
      case error.POSITION_UNAVAILABLE:
      txt = 'Location position unavailable';
      break;
      case error.TIMEOUT:
      txt = 'Location position lookup timed out';
      break;
      default:
      txt = 'Unknown position.'
    }
    alert(txt)
  }
  //Reinitialise entry_page when it is revisted again
  $(document).on("pageshow", "#entry_page", function()
  {
    if (navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(onSuccess, onError, {timeout: 30000});
    }
    changeHeaderName("#chickenNameHeader");
    clearFields();
});
P.S. I'm using Nginx and Nodejs. My Nginx is configured for https.
 
     
    