【问题标题】:Getting error - ERROR TypeError: Cannot read property 'constructor' of undefined - in IONIC Native Google Maps出现错误 - 错误类型错误:无法读取未定义的属性“构造函数” - 在 IONIC Native Google Maps 中
【发布时间】:2019-12-06 00:07:46
【问题描述】:

我已将 Google 地图集成到我的 Ionic 3 应用程序中,它运行良好,但一段时间后它停止运行。它给了我错误ERROR TypeError: Cannot read property 'constructor' of undefined

所以我卸载了 Ionic Native Google Maps 插件,并按照here 的建议再次安装。

但是当我安装它时,它给了我一个错误TypeError: Object(...) is not a function for ionic native core,它让我的应用程序崩溃了。所以我再次将离子原生核心插件降级为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();
  }
}

【问题讨论】:

    标签: google-maps ionic-framework ionic3


    【解决方案1】:

    我遇到了同样的问题,也必须降级原生核心,我只是将地图插件降级到 4.21.0

    npm install @ionic-native/google-maps@4.21.0
    

    此版本仍支持 Ionic 3 内核

    【讨论】:

    • 感谢您的回复,但我已将 javascript SDK 用于谷歌地图,但会尝试一下
    猜你喜欢
    • 2012-12-16
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2020-09-07
    • 1970-01-01
    • 2021-12-03
    • 2021-11-22
    相关资源
    最近更新 更多