我正在尝试将基本地图加载到我的模板上。我只是按照这个说明操作https://ionicframework.com/docs/native/google-maps/ 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.component.ts 文件中打印 console.log
我更改了 app.module.ts 文件
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}
]
只需从我的提供商中删除 googleMap 并导入我就可以使用了
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)