【问题标题】:Native: tried accessing the GoogleMap plugin but it's not installed本机:尝试访问 GoogleMap 插件,但未安装
【发布时间】:2017-05-11 05:02:10
【问题描述】:

试图在 ionic 2 中实现 google maps (native),尝试了各种方法,但都是徒劳的。

试用过:

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

错误:

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

安装 GoogleMap 插件:'ionic plugin add 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!');
    });

}

}

有人可以帮助如何继续进行此操作吗?

【问题讨论】:

    标签: google-maps ionic2


    【解决方案1】:

    遇到同样的问题。这对我有用。很快,你应该把你的代码放在ngAfterViewInit()而不是constructor()

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

    【讨论】:

      【解决方案2】:

      使用来自josh morony 的本教程,它包含在 ionic 2 中添加谷歌地图所需的所有信息

      【讨论】:

        猜你喜欢
        • 2017-10-28
        • 2018-04-24
        • 2021-11-10
        • 1970-01-01
        • 2019-03-09
        • 2020-10-16
        • 1970-01-01
        • 2014-09-25
        • 1970-01-01
        相关资源
        最近更新 更多