Ionic Native Geolocation not working on Android

Hi All,

I have the following code using Ionic Native Geolocation:

import { Geolocation } from 'ionic-native';

    this.platform.ready().then(() => {
        alert('loadMap about to getCurrentPosition');
          Geolocation.getCurrentPosition(options).then((position) => {
        alert('loadMap getCurrentPosition');
            let latLng: google.maps.LatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            bound.extend(latLng);
            this.load(bound);
          });
    });

When I run this as ionic serve in a browser, or I build it and run it on iOS Simulator (Xcode), it works. However, when I build this for Android, and try run it, the first alert gets fired, but not the second.

That means for Android only, Geolocation.getCurrentPosition... is not working.

Does anyone know what I am doing incorrectly, or if there are some missing steps in the Android install and build process?

Thanks

1 Like

Maybe remove/add the plugin again?

I don’t use ionic native for geolocation but I could confirm that the plugin, version 2.4.1, works on android (at least on real device).

I do:

navigator.geolocation.getCurrentPosition(
     (data:any) => {
        // Stuffs
     }, (error:any) => {
       // Error stuffs
    });

Also in my index.html, after ion-app declaration I’ve got:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=REPLACE_WITH_YOUR_KEY&amp;libraries=places,geometry"></script>
1 Like

I deployed it to my Android phone and it works, it gets the location. So I guess the problem is with the Android Emulator. But I can live with this because the Emulator is just for testing as is the phone.

Than you for your help.

Cool, good to know. I could never use the android emulator because the use of crosswalk make me face the white screen of death, therefor I also always test on real android phone too.

1 Like