3 Replies Latest reply on Jun 16, 2016 1:12 PM by kerrishotts

    cordova-plugin-geolocation not giving location for Android

    keshavb32400163

      I am using Phonegap and i am using cordova-plugin-geolocation. It is working fine for IOS but for Android i am not able to get location most of the times. Even if i get the location, it is not accurate.


      Thanks in advance

       

       

      Thanks!!

        • 1. Re: cordova-plugin-geolocation not giving location for Android
          kerrishotts Adobe Community Professional

          Which version of the plugin are you using?

           

          Can you share some of your code where you're asking for a location? It might help us troubleshoot the issue.

           

          Also, check the device's log files (adb logcat) -- there might be some useful information lurking in there.

          • 2. Re: cordova-plugin-geolocation not giving location for Android
            keshavb32400163 Level 1

            HI,

             

            I am using cordova-plugin-geolocation version="2.1.0". Can you please let me know if there is restriction for the Android version on which it will not behave properly ?

             

            Here is a sample code for getting location :

             

            function (successCallback, errorCallback){

                 navigator.geolocation.getCurrentPosition(function(position){

                      successCallback(position);

                  }, function(error) {

                        errorCallback(error);

                  } , {timeout: 3000});

            }

             

            Thanks!!!

            • 3. Re: cordova-plugin-geolocation not giving location for Android
              kerrishotts Adobe Community Professional

              Ok,

               

              When you don't get a location, does the errorCallback get called? If so, what is the error that is passed?

               

              Also, the timeout there is really short. It can take some time for a device to establish a satellite fix, so I'd suggest providing a longer timeout.

               

              Further, you aren't asking for a high accuracy response. Add "enableHighAccuracy: true" to your options object. That should help, although there's no guarantee here. (Device geolocation can vary wildly depending upon the internal components of the device, the available methods of determining location, satellite availability, etc.)

               

              Lastly, geolocation can often be a bit noisy, especially as the device is pinning down a user's location (there's lots of ways a device can try and figure out where you are). So you may want to watch a position over a given period of time to try and come up with a better result (with more data you can reject obviously inaccurate results).