【问题标题】:Ionic 2: use HtmlInfoWindow in native cordova-plugin-googlemapsIonic 2:在原生 cordova-plugin-googlemaps 中使用 HtmlInfoWindow
【发布时间】:2017-12-21 14:03:40
【问题描述】:

我在我的应用程序中使用了 cordova-plugin-googlemaps。 https://ionicframework.com/docs/native/google-maps/

我的代码:

  loadMap() {

    var element: HTMLElement = document.getElementById('map');
    var map: GoogleMap = this.googleMaps.create(element);
    map.one(GoogleMapsEvent.MAP_READY).then(() => {

      var ionic: LatLng = new LatLng(50.5279314,30.2317489);

      var position: CameraPosition = {
        target: ionic,
        zoom: 10,
      };
      map.moveCamera(position);

      var htmlInfoWindow = new HtmlInfoWindow();
      htmlInfoWindow.setContent('<div>Test</div>');

      map.addMarker({
        position: new LatLng(50.5279314,30.2317489),
      }).then((marker: Marker) => {
        marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
          htmlInfoWindow.open(marker);
        });
      });

    });

  }

当我尝试打开 HtmlInfoWindow 时,出现错误。请帮忙:

console.error:未处理的承诺拒绝:marker.bindTo 不是 功能。 (在'marker.bindTo("infoWindowAnchor", self)'中, 'marker.bindTo' 未定义);区域:;任务:空;价值: [对象对象] http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/HtmlInfoWindow.js:233:22 fromLatLngToPoint@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/Map.js:620:26 open@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/HtmlInfoWindow.js:229:26 http://192.168.0.104:8102/build/vendor.js:56416:25 t@http://192.168.0.104:8102/build/polyfills.js:3:15045 tryNativePromise@http://192.168.0.104:8102/build/vendor.js:56415:31 http://192.168.0.104:8102/build/main.js:85:40 __tryOrUnsub@http://192.168.0.104:8102/build/vendor.js:31152:20 next@http://192.168.0.104:8102/build/vendor.js:31099:34 _下一个@http://192.168.0.104:8102/build/vendor.js:31039:30下一个@http://192.168.0.104:8102/build/vendor.js:31003:23 listener@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/BaseClass.js:60:21dispatchEvent@[本机代码] 触发@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/BaseClass.js:43:27 _onMarkerEvent@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/Map.js:982:23 nativeCallback@http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/googlemaps-cdv-plugin.js:313:32 nativeCallback@[本机代码] dispatchEvent@[本机代码] fireDocumentEvent@http://192.168.0.104:8102/cordova.js:235:35 global 代码@http://192.168.0.104:8102/:1:37

【问题讨论】:

  • 看到这个link
  • 我看到了这个链接,但没有帮助

标签: cordova google-maps ionic2 google-maps-markers cordova-plugins


【解决方案1】:

ionic 团队好像忘了实现 BaseClass 的bindTo 方法。

我发送了一个拉取请求。应该可以。

https://github.com/ionic-team/ionic-native/pull/1815

【讨论】:

  • 由于某种原因,我一直在等待 ionic 团队合并拉取请求。
  • 拉取请求已被接受。请重新安装插件。
  • 嗨@wf9a5m75,我今天更新了我的插件,但它仍然无法正常工作。当我调用htmlInfoWindow.open(marker); 时,它会抛出一个错误:TypeError: Object [object Object] has no method 'getId'
  • 请在github仓库的issue list上报告。那我来帮你。这不是跟进您的问题的好地方。 github.com/mapsplugin/cordova-plugin-googlemaps/issues
  • 该错误已在@ionic-native/core 和@ionic-native/google-maps ver4.2.0 中修复,请重新安装这两个包。 npmjs.com/package/@ionic-native/corenpmjs.com/package/@ionic-native/google-maps
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
  • 2016-12-20
  • 2016-10-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多