Get coordinates from Hardware GPS

Viewed 8953

I've found a lot of questions about GPS Coordinates but not one that confirms using the mobile hardware GPS instead of Web GPS like geoLocation and such like.

My actual method:

I'm using navigator.geolocation.getCurrentPosition(), the Lat/Long comes from the Web, here's the code:

function getGPS(funcCallBack)
{
   if (navigator.geolocation)
   {
     var timeoutVal = getCookie("GPSTimeout");
     navigator.geolocation.getCurrentPosition(sucess
                                             ,error
                                             ,{enableHighAccuracy: true
                                              ,timeout: timeoutVal
                                              ,maximumAge: 0}
                                             );
   }
   else{
   alert('GPS is turned off, or was not possible to find it. Now, doing the login without localization.');
   window.gpsLat = 0;
   window.gpsLng = 0;
   window.gpsAcc = 0;
   funcCallBack();
   }
   function sucess(position) //sucess
   {
      window.gpsLat = position.coords.latitude;
      window.gpsLng = position.coords.longitude;
      window.gpsAcc = position.coords.accuracy;
      funcCallBack();
    }
    function error()         //error
    {
      window.gpsLat   = 0;
      window.gpsLng   = 0;
      window.gpsAcc   = 0;
      funcCallBack();
    }
}

My problem:

Sometimes when I do the login I am not getting the GPS Coordinates (they come 0) and sometimes I am getting coordinates with more than 2,000 Accuracy (that is not precise).

By the way, I am testing the GPS on a data internet service, when I do use a Wi-Fi connection it works perfectly with less than 100 Accuracy.

Details:

Maybe you are complaining about:

  1. timeoutVal: it is a cookie with the number 5000 inside it.
  2. funcCallBack: it is a function that continues the login operation.
  3. window.gpsLat: it is a global var containing the Latitude value got from the geoLocation.
  4. window.gpsLng: it is a global var containing the Longitude value got from the geoLocation.
  5. window.gpsAcc: it is a global var containing the Accuracy value got from the geoLocation.

What do I want?

I want a solution in JavaScript or PHP that can get coordinates from the mobile hardware device, the Native GPS, not the geolocation, and when the Native GPS is turned off, ask the user to turn it on.

2 Answers
Related