Native:尝试访问GoogleMap插件,但未安装

时间:2017-03-23 05:43:36

标签: google-maps ionic2

试图在离子2中实现谷歌地图(原生),尝试了各种各样的事情,但都是徒劳的。

试过:

https://forum.ionicframework.com/t/google-maps-typescript-error-cannot-find-name-google-discussion/49990

错误:

Native:尝试访问GoogleMap插件但未安装。

安装GoogleMap插件:'离子插件添加plugin.google.maps.Map'

尝试安装上述插件时,它说:

错误:注册表在https://registry.npmjs.org/plugin.google.maps.Map

上为GET返回404

HTML -

<ion-content padding>
 <div #map id="map" ></div>
</ion-content>

JS -

import { Component } from '@angular/core';
import { NavController, NavParams, Platform } from 'ionic-angular';
import { GoogleMap, GoogleMapsEvent, GoogleMapsLatLng } from 'ionic-native';
@Component({
  selector: 'page-store-map',
  templateUrl: 'store-map.html'
})
export class StoreMapPage {
map: GoogleMap;

constructor(public navCtrl: NavController,public platform: Platform, 
public navParams: NavParams) { 
platform.ready().then(() => {
  alert('Ready');
  this.loadMap();
});
}
 ionViewDidLoad() {
console.log('ionViewDidLoad StoreMapPage');
}

loadMap()
{

    let location = new GoogleMapsLatLng(-34.9290,138.6010);

    this.map = new GoogleMap('map', {
      'backgroundColor': 'white',
      'controls': {
        'compass': true,
        'myLocationButton': true,
        'indoorPicker': true,
        'zoom': true
      },
      'gestures': {
        'scroll': true,
        'tilt': true,
        'rotate': true,
        'zoom': true
      },
      'camera': {
        'latLng': location,
        'tilt': 30,
        'zoom': 15,
        'bearing': 50
      }
    });

    this.map.on(GoogleMapsEvent.MAP_READY).subscribe(() => {
        console.log('Map is ready!');
    });

}

}

有人可以帮忙解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

遇到同样的问题。这对我有用。不久,您应该将代码放在ngAfterViewInit()而不是constructor()

ngAfterViewInit() {
  this.platform.ready().then(() => {
    this.loadMap();
  });
}

答案 1 :(得分:-3)

josh morony使用本教程,它包含在离子2中添加Google地图所需的所有信息