5

根据文档,信息窗口中的标记是可选的,请问这是如何实现的?我试过infowindow.open(map)infowindow.open(map,null)但都没有产生任何结果。

4

3 回答 3

9

如果设置了位置,显示信息窗口没有问题

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);
}
于 2016-05-18T09:38:38.817 回答
5

infowindow.open(map)没有意义,因为您需要指定信息窗口应该打开的位置,它还有一个锥形杆,指定它应该指向的位置。

根据Infowindows的文档, InfoWindows 可以附加到标记对象(在这种情况下,它们的位置基于标记的位置)或地图本身的指定 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);

希望能消除您的疑虑。

于 2012-11-01T10:28:09.490 回答
2

由于 api 已更改,因此无法再在信息窗口上设置位置。我找到的解决方案是在地图上添加一个可见性为假的标记:

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);
      });
于 2018-11-06T13:59:51.977 回答