google-maps - Ionic native Google map 无法正确显示

标签 google-maps ionic-framework cordova-plugins ionic3

几周前,我遇到了 Google map ionic native 模块的问题,我做了一个 question (未解决)。


现在我在空白页面中进行测试,并且显示了 map ,但它看起来像:

enter image description here

这是我的 xml 文件,其中有包含 map 的 div。

<ion-header>
  <ion-navbar>
    <ion-title>maptest</ion-title>
  </ion-navbar>
</ion-header>

<ion-content style="background: pink;">
  <div #map id="map" style="height: 80%;"></div>
</ion-content>

这里我们有 ts 文件。这里我使用 ViewChild 创建 map

import { Component, ViewChild, ElementRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import {
  GoogleMaps,
  GoogleMap,
  CameraPosition,
  LatLng,
  GoogleMapsEvent,
  GoogleMapOptions
 } from '@ionic-native/google-maps';

/**
 * Generated class for the MaptestPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-maptest',
  templateUrl: 'maptest.html',
})
export class MaptestPage {
  @ViewChild('map') mapElement: ElementRef;
  map: GoogleMap;

  constructor(public navCtrl: NavController, public navParams: NavParams, private _googleMaps: GoogleMaps) {
  }

  ngAfterViewInit() {
    console.log('ngAfterViewInit');
    this.initMap();
  }

  initMap() {    
    let element = this.mapElement.nativeElement;
    this.map = GoogleMaps.create(element, {});//this._googleMaps.create(element);


    // Wait the MAP_READY before using any methods.
    this.map.one(GoogleMapsEvent.MAP_READY).then(() => {
      console.log('Map is ready!');

    }).catch( err =>{
      console.error("Error maperino --> "+err);
    });
  }

  moveCamera(location: LatLng) {
    let options = {
      target: location,
      zoom: 18,
      tilt: 30
    }

    this.map.moveCamera(options);
  }

}

我不知道我做错了什么:(

最佳答案

由于您可以看到 Google Logo ,因此您的代码没有问题。

问题在于您的 api key 。

您需要尝试重新生成 API key ,然后重新安装。 确保您生成 API key 之前启用了 google map android api v2 和适用于 ios 的 google map sdk。

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v1.4.0/TroubleShooting/Blank-Map/README.md

即使您尝试了这些步骤,但仍然得到灰色 map ,请直接与我联系。我会检查一下。

关于google-maps - Ionic native Google map 无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47885985/

相关文章:

未找到 Android SDK。确保它已安装。如果不在默认位置,设置ANDROID_HOME环境变量

javascript - 用于获取谷歌地图中标记位置的js代码不起作用

android - 从android中的数据库获取经纬度值

google-maps - 带有大陆轮廓/边界的 KML 文件

javascript - Google Maps V3 中没有设定目的地的最短路线?

javascript - Ionic 3在html模板中设置值

android - “Ionic cordova build android”错误

android - 用于将 keyUp 事件的键码传递给应用程序的 Cordova 插件

android - 如何通过蓝牙 (LE) 将图像传输到桌面应用程序

android - 用于在 iOS 和 Android 锁屏上显示音频信息和控件的 Cordova 插件