Default example for Android Geolocation fails - this is bad


#1

Hi there, still struggling with Android geolocation and the problem seems to be more serious than I thought because it comes up with the standard example.

I start from the empty blank project, add the cordova geolocation plugin, add few lines of code. Yet it fails with a timeout on a physical Android phone (6.0). Can it really be that the plugin is not supported for Droid > 5.1 as stated on the repo page?

ionic start geoTest blank --v2

ionic platform add android
ionic plugin add cordova-plugin-geolocation

open ./src/app/app.component.ts

Adding :

import { StatusBar, Splashscreen,Geolocation } from 'ionic-native';

platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      Splashscreen.hide();
      Geolocation.getCurrentPosition({ maximumAge: 60000, timeout: 30000, enableHighAccuracy: true }).then((position) => {
        console.log(position);
      }, (error) => {
        console.log(error);
      });
});

Keeps giving me timeouts / error 3.

Android manifest file contains
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.hardware.location.gps


#2

have you tried running it in actual physical device?
there maybe an issue with running geolocation in emulators


#3

Yes, real phone. Simulator fails too. iOS and browser run smooth.


#4

this is how im doing it, and its working on my side: (K,L,M&N android versions)
Geolocation.getCurrentPosition().then((position) => {

		this.lat = position.coords.latitude;
		this.lng = position.coords.longitude;
		this.pos_details = JSON.stringify(position);
		console.log('Position retrieved:'+this.lat+' '+this.lng);

	    }, (err) => {
	      console.log(err);
    });

Try to restart you phone and removing the app first.
Also, try removing the options and see if something changes, that might help


#5

Dude, I owe you one. I believe that the manifest file was not over written and hence the app didnt have the ability to geolocate. Delete app, reboot, restart worked. Yet, this should be mentioned somewhere as a known quirk.


#6

Could you be more explicit ?