2017-04-15 95 views
2

我使用离子框架,但在整合谷歌地图时出现此错误:错误:未捕获(承诺):错误:没有GoogleMaps的提供者!错误:未被捕获(诺言):错误:没有GoogleMaps供应商

这是我的地图类:只能查看后

 import { Component,ViewChild } from '@angular/core'; 
     import { NavController,Platform } from 'ionic-angular'; 
     import { App, MenuController } from 'ionic-angular'; 
    import { 
    GoogleMaps, 
    GoogleMap, 
    GoogleMapsEvent, LatLng, 
    CameraPosition, 
    MarkerOptions, 
    Marker 
} from '@ionic-native/google-maps'; 
import { HttpModule } from '@angular/http'; 
import { NgModule } from '@angular/core'; 



    @NgModule({ 
imports: [ 
    HttpModule 
]}) 
@Component({ 
selector: 'page-home', 
templateUrl: 'home.html' 
}) 
export class HomePage { 

map: GoogleMap; 
constructor(public platform: Platform,public navCtrl: 
    NavController,app: App, menu: MenuController,private googleMaps: 
     GoogleMaps) { 

    menu.enable(true); 
     platform.ready().then(() => { 
     this.loadMap(); 
      }); 

     } 

     @ViewChild('map') mapElement; 

//加载地图初始化 loadMap(){

 let location = new LatLng(-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!'); 
    }); 

} 

}

回答

17

您需要将提供程序添加到在NgModule,在供应商即module.ts,

providers: [ 
    GoogleMaps 
] 
+0

仍然得到同样的错误。如果你能否详细说明这将是一个GR8帮助 –

+0

你在哪里增加吗? – Sajeetharan

+0

同一类的NgModule下 –