下面的代码,我用它来在我的页面中显示地图。
-
TS 文件
import { GoogleMaps, GoogleMap, GoogleMapsEvent, LatLng, CameraPosition, MarkerOptions, Marker } from '@ionic-native/google-maps'; export class MapPage { constructor(private googleMaps: GoogleMaps){} ngAfterViewInit() { this.loadMap(); } loadMap() { let element: HTMLElement = document.getElementById('map'); let map: GoogleMap = this.googleMaps.create(element); map.one(GoogleMapsEvent.MAP_READY).then(() => { console.log('Map is ready!'); }); } }
-
网页代码块
<div #map id="map" style="height:100%;"></div>
由于您使用的是 Ionic Native 的Google Maps
,因此它无法在浏览器上运行。Ionic Native
/Cordova plugins
仅在模拟器/真实设备中工作