angular – ionic 4 google-maps 5 beta“TypeError:无法读取属
发布时间:2020-12-17 18:07:09 所属栏目:安全 来源:网络整理
导读:我试图使用离子4 google-maps@5.0.0-beta.20 我正在关注这些幻灯片:https://docs.google.com/presentation/d/1zlkmoSY4AzDJc_P4IqWLnzct41IqHyzGkLeyhlAxMDE/edit#slide=id.g282d0a7bfd_0_140 我收到此错误:“TypeError:无法读取属性’BaseClass’的null
我试图使用离子4 google-maps@5.0.0-beta.20
我正在关注这些幻灯片:https://docs.google.com/presentation/d/1zlkmoSY4AzDJc_P4IqWLnzct41IqHyzGkLeyhlAxMDE/edit#slide=id.g282d0a7bfd_0_140 我收到此错误:“TypeError:无法读取属性’BaseClass’的null” newlocation.page.html: <ion-content> <h3>Ionic GoogleMaps Starter</h3> <div id="map_canvas"> </div> </ion-content> newlocation.page.scss: map_canvas { height: 90%; } newlocation.page.ts: import { Component,OnInit } from '@angular/core'; import { Platform } from '@ionic/angular'; import { GoogleMaps,GoogleMap } from '@ionic-native/google-maps'; @Component({ selector: 'app-newlocation',templateUrl: './newlocation.page.html',styleUrls: ['./newlocation.page.scss'],}) export class NewlocationPage implements OnInit { map: GoogleMap; constructor(private platform: Platform) { } async ngOnInit() { await this.platform.ready(); await this.loadMap(); } loadMap() { this.map = GoogleMaps.create('map_canvas'); } } 的package.json: .... "@ionic-native/core": "5.0.0-beta.14","@ionic-native/google-maps": "^5.0.0-beta.20" .... "cordova-plugin-googlemaps": { "API_KEY_FOR_ANDROID": (API-KEY),"PLAY_SERVICES_VERSION": "15.0.1","ANDROID_SUPPORT_V4_VERSION": "27.+" } 解决方法
在Ionic V4中,我们需要定义loadMap()方法异步调用,它将返回promise.
async ngOnInit() { await this.platform.ready(); await this.loadMap() } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |