Navigator geolocation getCurrentPosition work/not work


#1

I all, I have a problem, in my bq aquarius 5hd, navigator.geolocation.getCurrentPosition work, but in my kurio no (Error(3): Timeout expired) :confused: please help me

(it is my code)

var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };
    
    function success(pos) {
      var crd = pos.coords;
    
      alert('Your current position is:');
      alert('Latitude : ' + crd.latitude);
      alert('Longitude: ' + crd.longitude);
      alert('More or less ' + crd.accuracy + ' meters.');
    };
    
    function error(err) {
      alert('ERROR(' + err.code + '): ' + err.message);
    };
    
    navigator.geolocation.getCurrentPosition(success, error, options);
    	
    })

#2

If you’re not using the Cordova geolocation plugin but relying on the built in geolocation functions of the browser, it could be your older device is failing because that version of the browser doesn’t support geolocation? This is just a guess.

If this is the case, I would try the plugin and see if that resolves your issue.


#3

Thanks @coen_warmer for the help, but I’m using the plugin above, already uninstalled it up and went back to install to have for certain that the latest version was the same but the error continues :confused:


#4

and the same thing, aquarius work, Kurio not …


#5

Hello,

  1. Did you find it ?

  2. Did you tried to replace this timeout: 5000 by this timeout: 30000 ?

  3. Did you check : if the version of Cordova that you used is compatible with your mobile appliance ?

++


#6

Tanks fabiolas, but problem is protection for minors not to give


#7

Problem is easily solvable if you:

I. Wrap your geolocation code in device ready event
II. Use Cordova Whitelist plugin

Find more about it in another forum post:


#8

@Gajotres

No matter what the timeout is set or whether the high accuracy is true or false !!
$cordovageolocation always returning error code 3 error message Timeout expired

Heres my code :-

$ionicPlatform.ready(function() {

          var posOptions = {
             enableHighAccuracy: false,
             timeout: 30000,
             maximumAge: 0
         };
   $cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
       var lat  = position.coords.latitude;
       var long = position.coords.longitude;
       //alert(lat);
       var FormData = {
         'radius' : $localStorage.nearradius,
         'latitude' : lat,
         'longitude' : long
       };
       $http({
         method: 'POST',
         url: 'http://xyz.com/abc',
         data: FormData,
         headers: {'Content-Type': 'application/x-www-form-urlencoded','Authorization':undefined},
       })
       .success(function(data) {
           defer.resolve(data);
       })
       .error(function(data) {
   });
   }, function(err) {
       alert(err.code+" "+err.message);
   });

It always goes in function(err) …

Code is wrapped inside ionic platform ready !

Help is appreciated !!


#9

@Sumeet123 Any solution? thanks


#10

There is no solution as such .

I have a custom rom installed on my android device.

In my app i have background geolocation working too.

Now the issue for me was ,

when i enable location services,gps etc. $cordovaGeolocation always times out.

If i disable all gps/location services it works correctly.

but its weird because background geolocation always works correctly locking the gps position.

For now, i am considering it as bug from my custom ROM. But this makes me think why does background geolocation work if its a ROM bug.

in your case config from previous post should work.


#11

So, cordova plugin geolocation dont work in actual version?


#12

no. it does work !

i have tested it on other devices. Test it on other device.

to check if its problem in your device

visit here http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation

from your mobile browser.

and check if its gives you your current lat long on clicking try it


#13

Using the plugin, as @Sumeet123, get error:
error code 3 error message Timeout expired

Using navigator.geolocation like:

if (navigator.geolocation) {
console.log(‘geolocation’);
navigator.geolocation.getCurrentPosition(function(position) {
console.log('navigator ok);
var lat = position.coords.latitude;
var lng = position.coords.longitude;

}, function(error) {

console.log('navigator error);
});
} else {
console.log(‘no geolocation’);
}

Show “geolocation” in console. But nothing more, or “navigator ok”, “navigator error” or some other error. In app android and emulator, with ionic last version. I’m making some mistake? Any alternative for current position?

thanks


#14

is it the actual code ? or its just a typing mistake ?

console.log('navigator ok); string not ending

should be console.log('navigator ok'); and same with console.log('navigator error');

log this console.log('navigator ok :'+lat+' '+lng); and console.log('navigator error '+JSON.stringify(error));


#15

Typing mistake…but console.log(‘navigator ok :’+lat+’ '+lng); or console.log('navigator error '+JSON.stringify(error)); not show!


#16

atleast one log should be shown ! since you logging at every step ,error too.

make sure you logging after defining the lat and lng variables.after var lat = position.coords.latitude; var lng = position.coords.longitude;

and there is no alternatives to html5 geolocation/$cordovageolocation


#17

Sorry, the problem was the emulator! Already solved. Thank you


#18

hi,
i set watcher and the water is triggering very frequently, even if i didnt move the device.
the difference bettween the prev location and the current location is in meters.
how to eliminate the error redings from the watcher?

thanks in advance


#19

I am facing same issue but in ionic 2. Any solution ?


#20

Did you able to solve it … I am facing the same issue