Navigator geolocation getCurrentPosition work/not work

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);
    	
    })

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.

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:

and the same thing, aquarius work, Kurio not ā€¦

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 ?

++

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

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:

@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 !!

@Sumeet123 Any solution? thanks

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.

So, cordova plugin geolocation dont work in actual version?

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

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

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));

Typing mistakeā€¦but console.log(ā€˜navigator ok :ā€™+lat+ā€™ '+lng); or console.log('navigator error '+JSON.stringify(error)); not show!

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

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

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

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

Did you able to solve it ā€¦ I am facing the same issue