google-maps - 收到错误 - ERROR TypeError : Cannot read property 'constructor' of undefined - in IONIC Native Google Maps

标签 google-maps ionic-framework ionic3

我已将 Google map 集成到我的 Ionic 3 应用程序中,它运行良好,但一段时间后它停止运行。它给我错误错误类型错误:无法读取未定义的属性“构造函数”

enter image description here 所以我卸载了 Ionic Native Google Maps 插件并按照建议再次安装 here

但是当我安装它时,它给了我一个错误TypeError: Object(...) is not a function for ionic native core,它使我的应用程序崩溃了。因此,我再次将 ionic 原生核心插件降级到 4.18.0(最新的是 v.5.10.0),应用程序再次开始工作,但我的谷歌地图仍然无法工作。

我的谷歌地图代码如下。

import {
   GoogleMaps,
   GoogleMap,
   GoogleMapsEvent,
   GoogleMapOptions,
   CameraPosition,
   MarkerOptions,
   Marker,
   Environment
 } from "@ionic-native/google-maps";
 export class MapPage {
   map: GoogleMap;
   constructor() {
   }
   ionViewDidLoad() {
      this.loadMap();
   }
   loadMap() {
      //https://github.com/ionic-team/ionic-native-google-maps/blob/master/documents/markeroptions/README.md'
      // This code is necessary for browser
      Environment.setEnv({
           API_KEY_FOR_BROWSER_RELEASE: "<MY_KEY>",
           API_KEY_FOR_BROWSER_DEBUG: "<MY_KEY>"
      });

      let mapOptions: GoogleMapOptions = {
        camera: {
          target: {
            lat: 25.284538,
            lng: 51.511393
          },
          zoom: 13,
          tilt: 30
         }
       };

  this.map = GoogleMaps.create("map_canvas", mapOptions);
  this.getMarkers();
  }
}

最佳答案

我遇到了同样的问题,也必须降级 native 核心,我只是将 map 插件降级到 4.21.0

npm install @ionic-native/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdaaa2a2aaa1a8e0a0acbdbe8df9e3fffce3fd" rel="noreferrer noopener nofollow">[email protected]</a>

该版本仍然支持 Ionic 3 核心

关于google-maps - 收到错误 - ERROR TypeError : Cannot read property 'constructor' of undefined - in IONIC Native Google Maps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57240482/

相关文章:

javascript - 将表达式连接到 html 标签的中间

javascript - 从状态设置工厂变量

html - 在 IONIC 上面的选项卡上放一个元素?

angular - 如何使用 ionic native 文件打开器打开(doc、ppt、xlsx、pdf、jpg、png)文件

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

java - Google map Activity 在 "getLastKnownLocation"中崩溃

google-maps - 我应该在 Google map URL 中使用哪些参数来获取经纬度?

android - 在 Android 中更改 Google map 填充时保持位置居中

Javascript - 显示和隐藏大量列表项的最快方法

css - ionic 网格布局对齐不正确