3

I am developing iPad application using phonegap (cordova 1.9.0). I need to get current position of the user. I used following code and it works fine when Location services are enabled.

function onDeviceReady() {  
 navigator.geolocation.getCurrentPosition(onSuccess, onError);   
 }

function onSuccess(position) {
 console.log(position.coords.latitude + "-" + position.coords.longitude);
}

  function onError(error) {   
     alert('code: '    + error.code           
      'message: ' + error.message + '\n');  
  }

My problem is that this code not working when Location services are disabled. I need to get current location if Location service are enabled or disabled.

Anyone tell me how to get current location in this situtation?

stay_hungry
  • 1,368
  • 1
  • 11
  • 21
Poorna
  • 323
  • 7
  • 19

1 Answers1

4

You can't get the current location when location services are disabled. That would be a violation of a user's privacy. The point of disabling location services on a device is to prevent applications from getting the current location.

What I've done is display my own dialog with a lengthy explanation of why I need location services before calling getCurrentPosition(). I explain that the app won't work without it. I also say something like:

Your device may also ask you for permission.

This increases the chances of someone saying yes to the iPhone dialog.

ThinkingStiff
  • 62,391
  • 29
  • 139
  • 237