0

我在我的应用中使用了cordova-plugin-googlemaps。 https://ionicframework.com/docs/native/google-maps/Ionic 2:在原生的cordova-plugin-googlemaps中使用HtmlInfoWindow

我的代码:

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: Unhandled Promise rejection: marker.bindTo is not a function. (In 'marker.bindTo("infoWindowAnchor", self)', 'marker.bindTo' is undefined) ; Zone: ; Task: null ; Value: [object Object] http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/HtmlInfoWindow.js:233:22 [email protected]http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/Map.js:620:26 [email protected]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 [email protected]http://192.168.0.104:8102/build/polyfills.js:3:15045 [email protected]http://192.168.0.104:8102/build/vendor.js:56415:31 http://192.168.0.104:8102/build/main.js:85:40 [email protected]http://192.168.0.104:8102/build/vendor.js:31152:20 [email protected]http://192.168.0.104:8102/build/vendor.js:31099:34 [email protected]http://192.168.0.104:8102/build/vendor.js:31039:30 [email protected]http://192.168.0.104:8102/build/vendor.js:31003:23 [email protected]http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/BaseClass.js:60:21 [email protected][native code] [email protected]http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/BaseClass.js:43:27 [email protected]http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/Map.js:982:23 [email protected]http://192.168.0.104:8102/plugins/cordova-plugin-googlemaps/www/googlemaps-cdv-plugin.js:313:32 [email protected][native code] [email protected][native code] [email protected]http://192.168.0.104:8102/cordova.js:235:35 global [email protected]http://192.168.0.104:8102/:1:37

+0

看到这个[链接](https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/tree/master/v2.0.0/class/HtmlInfoWindow/newHtmlInfoWindow) – Sabari

+0

我看到这个链接,但它并没有帮助 – wstudiokiwi

回答

1

看来离子团队忘了实施BaseClass的bindTo方法。

我发送了拉请求。应该管用。

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

+0

我一直在等待离子团队合并拉请求出于某种原因。 – wf9a5m75

+0

拉取请求已被接受。请重新安装插件。 – wf9a5m75

+0

嗨@ wf9a5m75,我今天更新了我的插件,但仍然无法正常工作。当我调用'htmlInfoWindow.open(marker);'它会抛出一个错误:'TypeError:Object [object Object]没有方法'getId'' – Duannx