【问题标题】:Google Maps infoWindow without marker?没有标记的谷歌地图信息窗口?
【发布时间】:2018-11-06 21:59:51
【问题描述】:

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

【问题讨论】:

  • 你想要什么,你试过什么,把代码贴在这里。

标签: maps infowindow


【解决方案1】:

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

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);
}

【讨论】:

    【解决方案2】:

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

    根据 Infowindows 的documentation - 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);

    希望能消除您的疑虑。

    【讨论】:

    • 欢迎。请考虑通过单击解决方案旁边的刻度线来标记答案:)
    【解决方案3】:

    由于 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);
          });
    

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-20
      相关资源
      最近更新 更多