【发布时间】:2017-06-02 17:11:04
【问题描述】:
我正在尝试将一张基本地图加载到我的模板上。我只是按照这个指令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
【问题讨论】:
标签: angular cordova google-maps ionic3