启动导航器无法在Ionic 4中打开Goog​​le地图

时间:2019-10-30 17:37:37

标签: google-maps ionic-framework

我在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运行android),并在手机上打开了该应用程序,但是当触发该NavigationLocation方法的按钮没有动作时,谷歌地图不会打开。

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

1 个答案:

答案 0 :(得分:0)

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

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