检查用户设备的GPS是否已打开

I am developing an app using jQuery Mobile with PHP. I am not using Phonegap or other frameworks. I need to find user's geolocation. If user device's GPS is off, then I cant get a location. now I need to find user device's GPS is on or off.

this is what i using now.

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  var lat=position.coords.latitude;
  var long=position.coords.longitude;
}

You can call this function on load

      // Function to get location
      function getLocation(){
          navigator.geolocation.getCurrentPosition(function (pos) {
              var lat = pos.coords.latitude;
              var lng = pos.coords.longitude;
              if (lat == null) {
                  alert("GPS not activated!");
              } else {
                  alert("Latitude: "+ lat + " , Longitude: " + lng );
              }
          });
      }

I just solved this one. I am using:

navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {maximumAge: 60000});

In the successCallback i written the codes for what it should do once I got the positions and in the error callback i wrote a simple alert message to prompt the user to turn the GPS on.

Please check this link to understand even if the GPS is turned off from device settings the GeoLocation api might still return some lat and long values.

https://security.stackexchange.com/questions/137418/how-does-google-know-where-i-am