运行时错误无法解析 GoogleMap 的所有参数:(?, ?) [英] Runtime Error Can't resolve all parameters for GoogleMap: (?, ?)

查看:17
本文介绍了运行时错误无法解析 GoogleMap 的所有参数:(?, ?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一张基本地图加载到我的模板上.我只是按照这个说明 https://ionicframework.com/docs/native/google-maps/ 让我的地图工作.

但我收到了类似上述问题的错误.

这是我的代码

//仅在视图初始化后加载地图ngAfterViewInit() {this.loadMap();}加载地图(){//确保在 view.html 文件中创建以下结构//并为其添加一个高度(例如 100%),否则地图将不可见//<离子含量>//<div #map id="map" style="height:100%;"></div>//</离子含量>//通过传递 HTMLElement 创建一个新地图让元素:HTMLElement = document.getElementById('map');让地图:GoogleMap = this.googleMaps.create(element);//监听 MAP_READY 事件//在向地图添加内容或以任何方式修改地图之前,您必须等待此事件触发map.one(GoogleMapsEvent.MAP_READY).then(() =>{console.log('地图准备好了!');//现在你可以像标记一样向地图添加元素});//创建 LatLng 对象让离子:LatLng = new LatLng(43.0741904,-89.3809802);//创建相机位置让位置:CameraPosition = {目标:离子,缩放:18,倾斜度:30};//将地图的相机移动到位置map.moveCamera(位置);}}

<块引用>

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

解决方案

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

从 '@ionic-native/google-maps' 导入 {GoogleMaps,GoogleMap};提供者:[状态栏,闪屏,谷歌地图,谷歌地图{提供:ErrorHandler,useClass:IonicErrorHandler}]

到这里

从 '@ionic-native/google-maps' 导入 {GoogleMaps};提供者:[状态栏,闪屏,谷歌地图{提供:ErrorHandler,useClass:IonicErrorHandler}]

只需从我的提供程序中删除 googleMap 并导入我就可以正常工作

i am trying to get an basic map to be loaded on my templet. I just followed this instruction https://ionicframework.com/docs/native/google-maps/ to get my map works.

But i am getting error like above question.

here is my code

// 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);

 }

}

i am getting blank screen i am not able to print console.log in my app.compontent.ts file

解决方案

I changed my app.module.ts file

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

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

To this

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

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

Just removing the googleMap from my provider and imports i got it worked

这篇关于运行时错误无法解析 GoogleMap 的所有参数:(?, ?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆