EliasM
EliasM

Reputation: 769

geolocation does not work ionic 3 - android

I have problem with plugin

import { Geolocation } from '@ionic-native/geolocation';

The geolocation does not work ionic 3 - ANDROID but in web browser from my computer its normal for me, this is my code:

export class TestPage {
  state: string = "";

  constructor(private geolocation: Geolocation,
    public platform: Platform) {

      this.platform.ready().then(() => {
        this.geolocation.getCurrentPosition().then((resp) => {
          // resp.coords.latitude
          // resp.coords.longitude
          this.state+="-"+resp.coords.latitude;
         }).catch((error) => {
          this.state+="-"+error.message;
        });
      });

  }
}

enter image description here

The result it´s above, I need your help, whats is the wrong??

Upvotes: 1

Views: 536

Answers (1)

Sampath
Sampath

Reputation: 65988

You need to use below CLI with Android device.It won't work with --livereload.

Reason: Google regards localhost as secure, but others as not.

ionic cordova run android --prod --device

You can read more about this issue here and here.

Upvotes: 1

Related Questions