Re: Function getGeolocation is not working on Android

18,091 views
Skip to first unread message

Erick the Redd

unread,
Oct 23, 2012, 2:02:48 AM10/23/12
to phon...@googlegroups.com
What version of Android are you testing on? What kind of device?

I have noticed that Samsung devices are very spotty with their GPS units. I have also noticed that ICS has some issues with GPS.

-- Eric

On Saturday, October 20, 2012 9:18:57 AM UTC-7, Mauricio Nunes wrote:
Hello friend;
I'm trying to use the function getGeolocation on Android, but this function is not working. Below is my code, but I don't have any result. 

<!DOCTYPE html>
<html> 
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
    <title>Map</title>
     
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
    
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript" src="cordova-2.1.0.js"></script>
     
    <script type="text/javascript">
      document.addEventListener("deviceready", onDeviceReady, false);
      
      // Cordova is ready
      //
      function onDeviceReady() {
     alert("onDeviceReady");
     navigator.geolocation.getCurrentPosition(onSuccess, onError,{ enableHighAccuracy: true });
      }

      // onSuccess Geolocation
      //
      function onSuccess(position) {
          var element = document.getElementById('geolocation');
          element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +
                              'Longitude: '          + position.coords.longitude             + '<br />' +
                              'Altitude: '           + position.coords.altitude              + '<br />' +
                              'Accuracy: '           + position.coords.accuracy              + '<br />' +
                              'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
                              'Heading: '            + position.coords.heading               + '<br />' +
                              'Speed: '              + position.coords.speed                 + '<br />' +
                              'Timestamp: '          + 
   position.timestamp                    + '<br />';
      }

      // onError Callback receives a PositionError object
      //
      function onError(error) {
          alert('code: '    + error.code    + '\n' +
                'message: ' + error.message + '\n');
      }

      
      
      
    </script>
  </head> 
  <body> 
 
    <div data-role="page" id="index">
      <div data-role="header" data-theme="b"><h1>Map Header</h1></div>
      <div data-role="content" style="padding:0;">
        <p id="geolocation">Loading...</p>
      </div>
      <div data-role="footer" data-theme="b"><h4>Map Footer</h4></div>
    </div>
  </body> 
</html>

Gwendolyn

unread,
Nov 7, 2012, 5:57:36 AM11/7/12
to phon...@googlegroups.com
I have the exact same problem. Both succes and error callbacks don't get triggered. Does anybody have a solution for this?

Op donderdag 25 oktober 2012 15:53:58 UTC+2 schreef Francois Masurel het volgende:
Same problem for me.

Geolocation in one of our app is working perfectly fine on a HTC Desire with Android but fails on a Galaxy S3 with Android 4.1.1 (Timeout error).

Any help will be greatly appreciated.

Francois
Bordeaux, France

Gwendolyn

unread,
Nov 7, 2012, 5:59:56 AM11/7/12
to phon...@googlegroups.com
Also on a Galaxy S3

Op woensdag 7 november 2012 11:57:36 UTC+1 schreef Gwendolyn het volgende:

Gwendolyn

unread,
Nov 7, 2012, 9:53:02 AM11/7/12
to phon...@googlegroups.com
I upgraded to the latest Android software (4.1.1) and it appears to be working now.

Op woensdag 7 november 2012 11:59:56 UTC+1 schreef Gwendolyn het volgende:

Yauri Edogawa

unread,
Mar 17, 2013, 12:17:15 PM3/17/13
to phon...@googlegroups.com
I'm using Galaxy S3 with Android 4.1.2. but it's not working
any solution??

Terry Collinson

unread,
Apr 15, 2013, 11:39:21 AM4/15/13
to phon...@googlegroups.com
Hi, I think you need to also set a timeout=xxxx with enableHighAccuracy. Getting GPS readings can take some time particularly if it is off or has just been turned on.

On Monday, 15 April 2013 10:56:53 UTC+2, Adrian Hara wrote:
I have the same problem on a Galaxy S3 with Android 4.1.2. Neither the success or error callbacks are getting called! Everything works fine on iOS or desktop web browsers.

I have found, however, that if I set "enableHighAccurracy" to "true", the success callback gets called after a long time (1-2 minutes).

Anyone know what's going on?

Jeremy

unread,
May 2, 2013, 10:58:38 AM5/2/13
to phon...@googlegroups.com
Hi,

I have the same issue on Samsung S2 running Android 4.1.2.  I get a 'Timeout expired' in my error callback.  The call to get the position is asynchronous so make sure you provide a callback.

The same code works on my HTC Evo running Android 4.0.3.

I am running PhoneGap 2.2.

Did you solve this?

Cheers

Chris Lambrou

unread,
May 3, 2013, 11:28:54 AM5/3/13
to phon...@googlegroups.com
For me it was uber important to set a timeout in the navigator call options.  Once I did that, the callbacks starting talking... Good luck.

-  navigator.geolocation.getCurrentPosition(gotLoco,noLoco,{frequency:5000,maximumAge: 0, timeout: 100, enableHighAccuracy:true}); 

Thread7

unread,
Sep 18, 2013, 12:48:59 AM9/18/13
to phon...@googlegroups.com
I had similar problems to the ones described in this thread.  The call to getCurrentPosition would not work or simply timeout on my Galaxy S3 device.  However, a Motorola Razr HD Maxx worked fine.  Once I changed the getCurrentPosition call to include MaximAge and "enableHighAccuracy: true" it worked.

Phil Merrell

unread,
Sep 30, 2013, 1:21:26 PM9/30/13
to phon...@googlegroups.com
Adding allowHighAccuracy: true, and a maximumAge parameter also worked for me with the Samsung S4.  Thanks!

Spaceman Spiff

unread,
Oct 9, 2013, 6:07:13 AM10/9/13
to phon...@googlegroups.com
I test on Samsung S2, impossible to make it work. I use Phonegap 2.9.0,  i added allowHighAccuracy: true, and a maximumAge parameter

Spaceman Spiff

unread,
Oct 9, 2013, 7:28:54 AM10/9/13
to phon...@googlegroups.com
I believe that this is related:



It worked when I moved nearby a window,  when I go back to my office it does not work.
I want to point out  that I don't work in a basement...
There must be something wrong with Galaxy devices.


johan baert

unread,
May 7, 2014, 3:57:11 AM5/7/14
to phon...@googlegroups.com
I had the same problem. I tried every setting of location services. I added allowHighAccuracy: true, and a maximumAge parameter, didn't work.

Then i rebooted my samsung tablet and it worked!!!

Never forget the basic rule. Did you reboot your device?

if only i had thought of it sooner it would have saved me 3 hours of searching for a solution.

cheers

Johan

Op woensdag 9 oktober 2013 13:28:54 UTC+2 schreef Spaceman Spiff:

julija....@privatbank.ua

unread,
May 8, 2014, 8:21:10 AM5/8/14
to phon...@googlegroups.com
I had same issue. I've restarted my device also. But it is not good decision. When user will use app he won't restart device each time it happened....

среда, 7 мая 2014 г., 10:57:11 UTC+3 пользователь johan baert написал:

shamaleyte

unread,
Oct 31, 2014, 4:16:10 PM10/31/14
to phon...@googlegroups.com
Hello Guys, 

First make sure that your code is bug free  ! 
If you are sure then you need to do one more thing ! 
Justchange the security settings of your Android device.
Go to Settings -> Security -> Check the "Unknown sources" checkbox
in order to allow your apk to be run without any problem.

Hope it works, 

Best, 

20 Ekim 2012 Cumartesi 19:18:57 UTC+3 tarihinde Mauricio Nunes yazdı:

Oscar Morales

unread,
Dec 9, 2014, 5:12:35 AM12/9/14
to phon...@googlegroups.com

Has anybody figured this out?

In my Galaxy SIII mini, after a few hours, the geolocation stops working and returns "timeout error" all the time. Then, I reboot the phone and starts working again.

You can't ask the user to reboot all the time. There's to be a solution!

shamaleyte

unread,
Dec 9, 2014, 8:12:18 AM12/9/14
to phon...@googlegroups.com
Hey Oscar,

getGeolocation is not working well for me too , that's why I run "watchGeolocation" and  listen to geolocation time till I get a geolocation info.
As soon as I get one , then I stop listening to the service and show the location on the map.

That could be a way around . But I am also curious about what is wrong with getGeolocation() .

Best,

9 Aralık 2014 Salı 12:12:35 UTC+2 tarihinde Oscar Morales yazdı:

Mike Programmer

unread,
May 7, 2015, 4:31:59 PM5/7/15
to phon...@googlegroups.com
I have the same issue with Samsung Galaxy SIII. Cordova geo functions are not working. It's my third day spend on that and this is impossible to force it to be working...

jcesarmobile

unread,
May 7, 2015, 5:07:43 PM5/7/15
to phon...@googlegroups.com
You can file an issue on the cordova jira page, but cordova android geolocation uses html5 geolocation now, so the problems are the webbviews, not cordova

Roman Venica

unread,
Dec 24, 2016, 3:56:54 PM12/24/16
to phonegap
Hello guys, wish this could help someboy:

I solved it setting a high timeout

navigator.geolocation.getCurrentPosition(onSuccess, onError, {timeout:3000, maximumAge:0, enableHighAccuracy:true }); 

It seems like old devices get much time to return True on getPosition(). 

(Srry for my english)

JAGANNATH MIDDYA

unread,
Sep 1, 2017, 3:33:40 PM9/1/17
to phonegap
Before checking your code please check once if the location service is on in your mobile.
Reply all
Reply to author
Forward
0 new messages