gpt4 book ai didi

angular - 谷歌本地 map 不适用于 ionic 3

转载 作者:太空狗 更新时间:2023-10-29 18:19:40 24 4
gpt4 key购买 nike

我关注了Google native maps for ionic 3但是遇到了错别字

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'BaseArrayClass' of null

针对上述错误进行了大量搜索,但找不到相关答案。我正在使用 *Angular4 和 ionic 3 *

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

<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

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

enter image description here

最佳答案

我在申请中遇到了同样的问题。我不知道这是否是最好的形状,但对我来说现在下定决心。 (抱歉,我的英语不是很好 rsrs)。

所以试着改变这个:

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

为此:

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

已编辑
我找到了解决问题的新方法。您需要在 package.json 中降级 @ionic-native/google-maps 的版本并执行 npm update 命令。

有可能是新版本的bug导致的。我项目中使用的版本是4.2.1

关于angular - 谷歌本地 map 不适用于 ionic 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46512511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com