android - 地理定位不起作用 ionic 3 - android

标签 android angular typescript geolocation ionic3

插件有问题

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

地理定位在 ionic 3 - ANDROID 中不起作用,但在我的计算机的网络浏览器中它对我来说很正常,这是我的代码:

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

结果就是上面的,我需要你的帮助,有什么问题吗??

最佳答案

您需要在 Android 设备 上使用以下 CLI。它不适用于 --livereload

原因:Google 认为 localhost 是安全的,但其他人则不是。

ionic cordova run android --prod --device

您可以阅读有关此问题的更多信息 herehere .

关于android - 地理定位不起作用 ionic 3 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47118094/

相关文章:

android - 应用类或服务中的 GPS?

android - 使用按钮控制音量

Angular - 获取格式,作为字符串,用于根据语言环境显示日期

angular - 无法使用 Angular 5 客户端启动与信号器核心中心的连接

unit-testing - 使用 jest.mock 和 TypeScript 而无需困惑的类型转换?

javascript - 无法将 userNm 的属性设置为未定义

PHP:如何从 android .apk 文件中获取版本?

Android 下拉列表(iPhone 风格)

angular - 使用对非 ASP .net 应用程序不起作用的 URL 重写从响应中删除服务器 header 。

java - 如何将 Angular 4 应用程序与 Spring Boot 堆栈集成?