Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi All,
I had created an application using phonegap. I had added geolocation plugin in application
C#
cordova plugin add org.apache.cordova.geolocation


I can able to see the plug in added in project.

Now I have created a location.html page in which I am using geolocation plugin :

C#
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>

    <script type="text/javascript">
        document.addEventListener("deviceready",onDeviceReady,false);

         function onDeviceReady(){
         alert("Device Ready");
          var options = { timeout: 60000 };
          var optionsLocation={maximumAge: 60000,timeout:120000, enableHighAccuracy: true };
        
         navigator.geolocation.getCurrentPosition(onSuccess,onError,optionsLocation);
         }

         function onSuccess(position)
         {
          alert("Yes, get location details..");

          var str='Latitude: '+ position.coords.latitude + 'Longitude: ' + position.coords.longitude ;
          alert(str);
        
         }

         function onError(error){
         alert("Oops, No location details available, Please check GPS is running..");
         switch(error.code)
              {
                  case error.PERMISSION_DENIED:
                  alert("User did not share geolocation data.");
                  document.getElementById('locationDetails').innerHTML="User did not share geolocation data.";
                  break;

                  case error.POSITION_UNAVAILABLE: alert("Could not detect current position.");
                   document.getElementById('locationDetails').innerHTML="Could not detect current position.";
                  break;

                  case error.TIMEOUT: alert("Retrieving position timedout,Please try again");
                   document.getElementById('locationDetails').innerHTML="Retrieving position timedout,Please try again";
                  break;

                  default: alert("unknown error");
                  break;
              }
         }
 </script>


I have specified 3 min as timeout, if I set this value to 10 min also getting same error Retrieving position timedout,Please try again

What is going wrong here? Not getting geo location details.

All GPS settings are enabled on phone. I can able to see my current location with Google Map application.

config.xml :
XML
<feature name="Geolocation">
    <param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>


Android manifest.xml :
XML
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />


Please guide to come out of this issue....

Thanks in advance for your help.

Regards,
Avinash
Posted
Updated 31-Mar-15 3:38am
v2
Comments
Global Speed Index 29-Jul-15 7:02am    
We have also been chasing this issue in 5.x (Lollipop). Thank you for bringing this issue to the forum! Please advise if you have made any progress in this topic :)
Kornfeld Eliyahu Peter 29-Jul-15 7:13am    
You may read this: http://dstromberg.com/2014/06/tutorial-using-the-html5-geolocation-api-in-phonegap-build/
Global Speed Index 30-Jul-15 6:43am    
Hey Kornfeid - Thanks for sharing this! GeoLocation is responsive, but with a request frequency of 400ms we consistently see actual responses occuring within the 3-4 second range, which confounds metrics and mapping.
Kornfeld Eliyahu Peter 30-Jul-15 6:46am    
GPS is a slow device...
Can you share your code? Maybe someone will spot the problem...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900