无法让AngularGoogleMapAGM与Angular11一起使用

我使用 npm 安装了 agm/core,如下所示:

npm install @agm/core

显示以下警告:

npm WARN @agm/core@3.0.0-beta.0 requires a peer of @angular/common@^9.1.0 || ^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @agm/core@3.0.0-beta.0 requires a peer of @angular/core@^9.1.0 || ^10.0.0 but none is installed. You must install peer dependencies yourself.

尽管如此,我还是继续按照如下文档将 AgmCoreModule 导入 AppModule:

AgmCoreModule.forRoot({
      apiKey: 'MY MAP KEY',
      libraries: ['places']
    })

但是,当尝试使用ng serve为应用程序提供服务时,会出现以下错误:

Error: node_modules/@agm/core/lib/services/google-maps-api-wrapper.d.ts:50:41 - error TS2314: Generic type 'MapHandlerMap<T>' requires 1 type argument(s).
50     subscribeToMapEvent<N extends keyof google.maps.MapHandlerMap>(eventName: N): Observable<google.maps.MapHandlerMap[N]>;
                                           ~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@agm/core/lib/services/google-maps-api-wrapper.d.ts:50:94 - error TS2314: Generic type 'MapHandlerMap<T>' requires 1 type argument(s).
50     subscribeToMapEvent<N extends keyof google.maps.MapHandlerMap>(eventName: N): Observable<google.maps.MapHandlerMap[N]>;
                                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@agm/core/lib/services/managers/marker-manager.d.ts:25:93 - error TS2694: Namespace 'google.maps' has no exported member 'MarkerMouseEventNames'.

25     createEventObservable<T extends (google.maps.MouseEvent | void)>(eventName: google.maps.MarkerMouseEventNames | google.maps.MarkerChangeOptionEventNames, marker: AgmMarker): Observable<T>;
                                                                                               ~~~~~~~~~~~~~~~~~~~~~
node_modules/@agm/core/lib/services/managers/marker-manager.d.ts:25:129 - error TS2694: Namespace 'google.maps' has no exported member 'MarkerChangeOptionEventNames'.39m

25     createEventObservable<T extends (google.maps.MouseEvent | void)>(eventName: google.maps.MarkerMouseEventNames | google.maps.MarkerChangeOptionEventNames, marker: AgmMarker): Observable<T>;

我已经在现有的 Angular 7 应用程序上进行了这项工作。但是我正在尝试升级到 Angular 11 并且在让 @agm/core 工作时遇到问题。

我也知道官方的 Angular google-map 组件,但我需要使用似乎与 agm 很好地集成的自动完成功能,并且找不到任何文档来使用 google-map 组件执行此操作。

有没有人成功地将@agm/core与 Angular 11 一起使用?
非常感谢帮助和建议。

回答

我有同样的问题,我在其他论坛中发现回滚谷歌地图的版本修复了它。我运行了以下命令,我能够看到它按预期工作。

npm i @types/googlemaps@3.39.13 --save-dev


以上是无法让AngularGoogleMapAGM与Angular11一起使用的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>