运行时错误无法解析GoogleMap的所有参数:(?,?)

时间:2017-06-01 13:52:10

标签: angular cordova google-maps ionic3

我正在尝试将一张基本地图加载到我的模板上。我只是遵循了这条指令https://ionicframework.com/docs/native/google-maps/来获取我的地图。

但我得到的错误就像上面的问题一样。

这是我的代码

// Load map only after view is initialized
ngAfterViewInit() {
 this.loadMap();
}

loadMap() {
 // make sure to create following structure in your view.html file
 // and add a height (for example 100%) to it, else the map won't be visible
 // <ion-content>
 //  <div #map id="map" style="height:100%;"></div>
 // </ion-content>

 // create a new map by passing HTMLElement
 let element: HTMLElement = document.getElementById('map');

 let map: GoogleMap = this.googleMaps.create(element);

 // listen to MAP_READY event
 // You must wait for this event to fire before adding something to the map or modifying it in anyway
 map.one(GoogleMapsEvent.MAP_READY).then(
   () => {
     console.log('Map is ready!');
     // Now you can add elements to the map like the marker
   }
 );

 // create LatLng object
 let ionic: LatLng = new LatLng(43.0741904,-89.3809802);

 // create CameraPosition
 let position: CameraPosition = {
   target: ionic,
   zoom: 18,
   tilt: 30
 };

 // move the map's camera to position
 map.moveCamera(position);

 }

}
  

我收到空白屏幕我无法在app.compontent.ts文件中打印console.log

1 个答案:

答案 0 :(得分:17)

我更改了我的app.module.ts文件

import {GoogleMaps,GoogleMap} from '@ionic-native/google-maps';

providers: [
    StatusBar,
    SplashScreen,
    GoogleMaps,
    GoogleMap
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]

到此

import {GoogleMaps} from '@ionic-native/google-maps';

providers: [
    StatusBar,
    SplashScreen,
    GoogleMaps
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]

只需从我的提供商处删除googleMap并导入即可使用