类型'Promise <void>'不能分配给'Marker'类型。 “Promise <void>”类型中缺少属性“_objectInstance”。离子2

时间:2017-04-01 21:59:10

标签: google-maps ionic-framework ionic2

我尝试在官方网站中应用离子2中的google地图文档中的内容:Ionic Docs Google Maps

我收到了这个错误:

Type 'Promise<void>' is not assignable to type 'Marker'. Property '_objectInstance' is missing in type 'Promise<void>'. Ionic 2

如下面的屏幕截图所示: enter image description here

2 个答案:

答案 0 :(得分:3)

我也有这个错误,我发现的解决方案是不使用标记变量,但只写

map.addMarker(markerOptions).then(...)

它有效,我的标记显示出来。

答案 1 :(得分:1)

试试这个:

 map.addMarker(markerOptions)
   .then((marker: Marker) => {
     marker.showInfoWindow();
   });

而不是

 const marker: Marker = map.addMarker(markerOptions)
   .then((marker: Marker) => {
     marker.showInfoWindow();
   });