谷歌地图infoWindow没有标记?

时间:2012-10-27 06:35:40

标签: maps infowindow

根据文档,一个标记是infoWindow可选的,那么如何实现呢?我已经尝试了 infowindow.open(map) infowindow.open(map,null)但两者都没有产生任何效果。

3 个答案:

答案 0 :(得分:7)

如果设置了位置,则显示信息窗口

没有问题
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 6,
  center: {lat: 55.6761, lng: 12.5683},
  mapTypeId: google.maps.MapTypeId.TERRAIN
});
var infowindow = new google.maps.InfoWindow({
  content: "Copenhagen"
});
infowindow.setPosition({lat: 55.6761, lng: 12.5683});
infowindow.open(map);
}

答案 1 :(得分:4)

infowindow.open(map)没有任何意义,因为你需要指定信息窗应该打开的位置,它也有一个锥形的茎,指定它应该指向的位置。

根据Infowindows的documentation - InfoWindows可以附加到Marker对象(在这种情况下,它们的位置基于标记的位置),也可以附加在地图本身的指定对象上LatLng。

因此,如果您不想让标记打开信息窗,请使用地图点击事件 -

var iwindow= new google.maps.InfoWindow;
    google.maps.event.addListener(map,'click',function(event)
    {
         iwindow.setContent(event.latLng.lat()+","+event.latLng.lng());
         iwindow.open(map,this); 
         iwindow.open(map,this);
    });

关闭InfowWindow- infowindow.setMap(null);

希望清除你的疑虑。

答案 2 :(得分:1)

由于api已更改,因此无法再在信息窗口中设置位置。我发现的解决方案是向可见性为false的地图添加标记:

this.map.addMarker({
        position: {
          'lat': sites[0].latitude,
          'lng': sites[0].longitude
        },
        // setting visible false since the icon will be the poi icon
        visible: false
      }).then((marker: Marker) => {

        this.htmInfoWindow.open(marker);
      });