2017-04-15 93 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下 –