Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation.latLng() not working in android

Tags:

meteor

cordova

I'm using mdg:geolocation package and I'm trying to run it in android device but I'm not getting lat and lang anymore, when I tried this few months back it is working fine

I'm using 1.0.3* version of that package

enter image description here

chrom is throwing above warning which takes me to this page

as it is a warning it should work.

I even tried to run the app by giving --mobile-server=https://myapp.com still it is not working.

any ideas?

My versions meteor - 1.1.* ( not the latest one) geolocation- 1.0.3

EDIT

I tried using navigator object like below

var onSuccess = function(position) {
   console.log('Latitude: '          + position.coords.latitude          + '\n' +
  'Longitude: '         + position.coords.longitude         + '\n' +
  'Altitude: '          + position.coords.altitude          + '\n' +
  'Accuracy: '          + position.coords.accuracy          + '\n' +
  'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
  'Heading: '           + position.coords.heading           + '\n' +
  'Speed: '             + position.coords.speed             + '\n' +
  'Timestamp: '         + position.timestamp                + '\n');
};

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

navigator.geolocation.getCurrentPosition(onSuccess, onError);

I didn't get any logs in console no error or success callbacks are called

EDIT 2:

This is not working when run my app in android mobile, If I run the same in web, I'm getting lat and lang values.

EDIT 3

I build apk with --server pointing to https://myapp.com still this is not working.

EDIT 4

I have one more project with all latest version, tried all the above steps still not working(even with build apk version)

EDIT 5

After trying @Adam suggestion I'm getting following error

code: 3 message: Timeout expired

tried different option with timeout, enablehighaccuracy and maxage nothing is working yet.

like image 326
Sasikanth Avatar asked Dec 26 '15 01:12

Sasikanth


2 Answers

With the Android emulator, you may have to provide a position first. So, run something like:

~/.meteor/android_bundle/android-sdk/platform-tools/adb emu geo fix <longitude value> <latitude value>
like image 151
Adam Avatar answered Oct 19 '22 15:10

Adam


You keep with your problem? I was avalaible to make it work by using

var geo_err = Geolocation.error();
if(geo_err != null) alert(geo_err.message);
var pos = Geolocation.latLng();
if(pos == null) return false;

You need to place it in a helper because it need to iterate over it waiting for a response, otherwise will give always an error. I use a button to change the state of a Session varible, which later activates the helper so it can be called more than once. Hope help, I tested in Android and chrome and works. The only problem was that I can't make the user to ask for permission, if the gps is not activated it gives me

Timeout error So... looking forward.

like image 22
Leonardo Maddio Avatar answered Oct 19 '22 16:10

Leonardo Maddio