如何在Google Maps v3的标记信息窗口中添加图片?

13

我有一张图片,名为stagleton.png,我想将它添加到一个标记上,并且我有一个创建标记的函数。如何更改InfoWindow方法,以便在InfoWindow中显示文本时也显示该图像?

function createMarker(name, latlng, mapsent)
{
    var marker = new google.maps.Marker({
                       position: latlng,
                       map: mapsent,
                       title: name   
                       });
    marker.info = new google.maps.InfoWindow({
              //when I add <IMG BORDER="0" ALIGN="Left" SRC="stagleton.jpg"> the maps will not load
      content: <IMG BORDER="0" ALIGN="Left" SRC="stagleton.jpg"> "My name is " + name

    });

    google.maps.event.addListener(marker, 'click', function(){
        marker.info.open(mapsent, marker);
    });
    return marker;
}
3个回答

25

尝试:

content: '<IMG BORDER="0" ALIGN="Left" SRC="stagleton.jpg"> My name is ' + name

3
@Dr.Molle,你在IE上尝试了吗?我无法在IE中打开包含图片的infoWindows。它们只是带有关闭按钮的小框,但没有其他内容。
一旦我移除了图片,其余的内容(h1标签、链接、文本)就能正常显示,infoWindow也会打开。
有什么线索吗?
编辑:必须在IMG标签中指定高度和宽度属性,IE才能渲染带有图片的infoWindow。IE是历史上最糟糕的浏览器,真是一个废物...
希望这能帮到某些人!

0
  var contentString = "<a href=/popups/" + id + '>' + name + "</a>" + '<br>' + address
  + '<br>' + category + '<br>' + "<img width='80' src=" + image + ">" ;

这对我有用。


检查一下我的答案,你在IE浏览器中测试了吗? - Sean Kendle

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接