【问题标题】:Gmaps API v3 -> infoWindow Content not showingGmaps API v3 -> infoWindow 内容未显示
【发布时间】:2013-04-10 05:54:26
【问题描述】:

我在我的网站上使用 Google Maps API v3 并尝试显示标记数组中的标记。

以下是相关代码:

var map;
var markersArray = [];
var infowindow;
var marker;

然后我将循环中的标记添加到数组中,调用以下函数

function addMarker(location, name) {
      marker = new google.maps.Marker({
      position: location,
      map: map,
      company: name,
      title: name
   });
   markersArray.push(marker);
}

然后我尝试使用此功能显示标记,这就像一个魅力:

function showOverlays() {
   if (markersArray) {
      for (var i in markersArray) {
         markersArray[i].setMap(map);
         google.maps.event.addListener(markersArray[i], 'click', function () {
         infowindow.setContent('<div style="height:300px; color:black">' + this.title +     '</div>');
         infowindow.open(map, this);
         });
      }
   }
}

现在我的问题来了:infoWindows 的内容没有显示出来。它打开了,但什么都没有显示... 如果我在其中放置一个 300px 高的 div,则 infoWindow 实际上会正确调整大小......但没有显示任何内容。

我已经在网上上下搜索并尝试摆弄它,但无济于事。

有没有人遇到过这种情况,可能会给我提示如何解决这个问题?

提前致谢!

克里斯

【问题讨论】:

    标签: javascript google-maps maps infowindow


    【解决方案1】:

    我刚刚发现了错误!

    我已经使用 CSS 设置了父 div(地图画布所在的 DIV)...并将 z-index 设置为 11。显然这阻止了信息窗口的内容位于顶部...

    希望能帮助一些可能犯过同样“错误”的人:)

    感谢 kevmc 的帮助

    【讨论】:

      【解决方案2】:

      我认为标记对象没有标题属性,您需要使用getTitle() 检索它:

      function showOverlays() {
         if (markersArray) {
            for (var i in markersArray) {
               markersArray[i].setMap(map);
               google.maps.event.addListener(markersArray[i], 'click', function () {
               infowindow.setContent('<div style="height:300px; color:black">' + this.getTitle() +     '</div>');
               infowindow.open(map, this);
               });
            }
         }
      }
      

      【讨论】:

      • 嗨 kevmc 感谢您的回复。当我插入警报(this.title)时,即使是 this.company,它也会提醒正确的值。问题实际上是 infoWindow 的内容没有显示/没有显示谢谢。
      • 如果您在信息窗口上使用网络检查器,它是否包含预期的标记?换句话说,它是窗口显示还是填充的问题)
      • 嗨,凯夫。填充作品,所有内容都可用,我可以 alert() 它没有任何问题。如果我将 infowindow.content 设置为 300px 高度的 div,则 infowindow 实际上会调整大小。但它没有显示里面的文字....
      • 我刚刚发现错误!我已经用CSS设置了父div(地图画布所在的DIV)......并将z-index设置为11。显然这阻止了信息窗口的内容在顶部......希望有帮助有些人可能会犯同样的“错误” :) 感谢 kevmc 的帮助!
      猜你喜欢
      • 1970-01-01
      • 2011-06-21
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2015-04-04
      • 2011-08-23
      相关资源
      最近更新 更多