2017-03-23 29 views
1

尝试在离子2中实施谷歌地图(原生),尝试了各种各样的东西,但都是徒劳的。原生:尝试访问GoogleMap插件,但未安装

试用:

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

错误:

母语:试图访问GoogleMap的插件,但它没有安装。

安装插件的GoogleMap:“离子插件添加plugin.google.maps.Map”

当试图安装上面的插件,它说:

错误:注册表返回404获得https://registry.npmjs.org/plugin.google.maps.Map

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!'); 
    }); 

} 

} 

有人可以帮助如何继续这个?

回答

3

加入谷歌地图得到了同样的问题的所有信息。这是为我工作的。不久之后,您应该将您的代码置于ngAfterViewInit()而不是constructor()

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