【问题标题】:Launch navigator does not open google maps in ionic 4启动导航器无法在 ionic 4 中打开谷歌地图
【发布时间】:2020-02-26 01:55:36
【问题描述】:

我在使用 ionic 4 开发的项目中使用启动导航器时遇到问题。

我输入了必要的命令:

ionic cordova 插件添加 uk.co.workingedge.phonegap.plugin.launchnavigator

npm install @ ionic-native / launch-navigator

在那之后,我将它们导入到 app.module 中。

这样,我实现了以下代码:

import { Component, OnInit } from '@angular/core';
import { LaunchNavigator, LaunchNavigatorOptions } from '@ionic-native/launch-navigator/ngx';
import { Geolocation } from '@ionic-native/geolocation/ngx';

@Component({
  selector: 'app-teste-gps',
  templateUrl: './teste-gps.page.html',
  styleUrls: ['./teste-gps.page.scss'],
})
export class TesteGpsPage implements OnInit {
  latitude: number;
  longitude: number;

constructor(private geolocation: Geolocation, private launchNavigator: LaunchNavigator) {
  }

ionViewDidLoad() {
    this.geolocation.getCurrentPosition().then(position => {
      this.latitude = position.coords.latitude;
      this.longitude = position.coords.longitude;
    }).catch(erro => {
      console.log(erro);
    })
  }


  navigateLocation() {
    let options: LaunchNavigatorOptions = {
      start: [this.latitude, this.longitude],
      app: this.launchNavigator.APP.GOOGLE_MAPS
    };

    this.launchNavigator.navigate('Laguna, SC', options)
      .then(success => {
        console.log(success);
      }, error => {
        console.log(error);
      })
  }

之后,我执行命令(ionic cordova run android),应用程序在我的手机上打开,但是当触发 navigateLocation 方法的按钮没有任何操作时,谷歌地图无法打开。

有人知道它是什么吗?如果是版本问题或类似问题?

【问题讨论】:

    标签: google-maps ionic-framework


    【解决方案1】:

    我怀疑这可能是您的 API 权限问题。请尝试以下操作:

    1. 访问Google Cloud。选择您的项目。
    2. 然后点击左侧菜单中的凭据部分。
    3. 页面加载后,在 API Keys 部分下,点击相关的 API key。
    4. 检查“应用程序限制”部分,确保所选选项满足您的目的。
    5. 出于测试目的,在“API 限制” 下选择“不限制密钥” 选项并保存。然后在 10 分钟后检查它是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      相关资源
      最近更新 更多