简体   繁体   English

谷歌原生地图不适用于离子3

[英]Google native map not working in ionic 3

I have followed Google native maps for ionic 3 but came across a typo 我已经关注了离子3的Google原生地图,但遇到了一个错字

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'BaseArrayClass' of null 错误错误:未捕获(在承诺中):TypeError:无法读取null的属性'BaseArrayClass'

Searched a lot on above error but could not find relevant answers. 对上述错误进行了大量搜索但未找到相关答案。 I am using *Angular4 with ionic 3 * . 我正在使用* Angular4和离子3 *

app.module.ts app.module.ts

 import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, NgModule } from '@angular/core'; import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; import { MyApp } from './app.component'; import { HomePage } from '../pages/home/home'; import { ListPage } from '../pages/list/list'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import {GoogleMaps} from '@ionic-native/google-maps'; @NgModule({ declarations: [ MyApp, HomePage, ListPage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), ], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage, ListPage ], providers: [ StatusBar, SplashScreen, GoogleMaps, {provide: ErrorHandler, useClass: IonicErrorHandler} ] }) export class AppModule {} 

home.html home.html的

 <ion-header> <ion-navbar> <button ion-button menuToggle> <ion-icon name="menu"></ion-icon> </button> <ion-title>Google Maps</ion-title> </ion-navbar> </ion-header> <ion-content padding> <div id="map"></div> </ion-content> 

home.ts home.ts

 import { GoogleMaps, GoogleMap, GoogleMapsEvent, GoogleMapOptions, LatLng, CameraPosition, MarkerOptions, Marker } from '@ionic-native/google-maps'; import { Component } from '@angular/core'; import { Platform, NavController } from 'ionic-angular'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { map: GoogleMap; mapElement: HTMLElement; constructor(public navCtrl: NavController, private googleMaps: GoogleMaps, public platform: Platform) { // Wait the native plugin is ready. platform.ready().then(() => { this.loadMap(); }); } ionViewDidLoad() { this.loadMap(); } loadMap() { this.mapElement = document.getElementById('map'); let mapOptions: GoogleMapOptions = { camera: { target: { lat: 43.0741904, lng: -89.3809802 }, zoom: 18, tilt: 30 } }; this.map = this.googleMaps.create(this.mapElement, mapOptions); // Wait the MAP_READY before using any methods. this.map.one(GoogleMapsEvent.MAP_READY) .then(() => { console.log('Map is ready!'); // Now you can use all methods safely. this.map.addMarker({ title: 'Ionic', icon: 'blue', animation: 'DROP', position: { lat: 43.0741904, lng: -89.3809802 } }) .then(marker => { marker.on(GoogleMapsEvent.MARKER_CLICK) .subscribe(() => { alert('clicked'); }); }); }); } } 

Added a error screenshot 添加了错误屏幕截图

在此输入图像描述

I have the same problem in my application. 我的申请中遇到同样的问题。 I don't know if this is the best shape but for me resolve for now. 我不知道这是不是最好的形状,但我现在决心。 (sorry, my english is not very good rsrs). (对不起,我的英语不是很好)。

So try change this: 所以尝试改变这个:

this.googleMaps.create(this.mapElement, mapOptions);

For this: 为了这:

this.map = new GoogleMap(this.mapElement, mapOptions);

EDITED EDITED
I found a new solution for the problem. 我找到了解决问题的新方案。 You need do downgrade the version of the @ionic-native/google-maps in package.json and execute npm update command. 您需要在package.json中降级@ ionic-native / google-maps的版本并执行npm update命令。

Its possible that problem occours because a bug in the new version. 由于新版本中的错误,可能会出现问题。 The version that I use in my project is 4.2.1 我在项目中使用的版本是4.2.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM