Javascript 如何将图像添加到谷歌地图 v3 中标记的信息窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10161013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:07:35  来源:igfitidea点击:

How to add an image to InfoWindow of marker in google maps v3?

javascripthtmlgoogle-maps

提问by Stagleton

I have an image that I want to add to a marker, stagleton.png, and I have a function to create a marker. How do I change the InfoWindow method so that the image is also displayed with the text in the InfoWindow?

我有一个要添加到标记的图像 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;
}

回答by Dr.Molle

Try:

尝试:

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

回答by Sean Kendle

@Dr.Molle, did you try that in IE? I can't get the infoWindows to open in IE any time they have an image inside of them. They are just tiny with the X to close it, but no other content.

@Dr.Molle,您在 IE 中尝试过吗?任何时候我都无法在 IE 中打开 infoWindows 里面有图像。它们很小,用 X 关闭它,但没有其他内容。

As soon as I remove the image, the rest of the content (h1 tags, links, text) shows fine, and the infoWindow opens.

一旦我删除了图像,其余的内容(h1 标签、链接、文本)就可以正常显示,并且信息窗口会打开。

Any clues??

有什么线索吗??



EDIT: You MUST specify height and width attributes in the IMG tag for IE to be able to render the infoWindow with an image in it. IE is the WORST browser in history, what a POS...

编辑:您必须在 IMG 标记中指定高度和宽度属性,以便 IE 能够呈现带有图像的信息窗口。IE 是历史上最糟糕的浏览器,多好的 POS...

Hopefully that helps someone!

希望这可以帮助某人!

回答by zero_cool

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

This worked for me.

这对我有用。