如何在 HTML 中使用 InfoWindow 将来自 url 的图像插入标记内?

How to insert an image from an url inside a marker with InfoWindow in HTML?

我已经在名为 photo 的变量中有 url 图像,在名为 url 的变量中有页面的 url,我想在我的 HTML

我正在尝试做这样的事情:

ContentString= '<img src= "photo" alt="url" />'

marker['infowindow'] = new google.maps.InfoWindow({
        content: ContentString

但是没有结果,正确的做法是什么?我读过 google 地图 API 并且他们为他们的标记创建了他们的结构-HTML 是这样的..

var contentString = '<div id="content">'+
  '<div id="siteNotice">'+
  '</div>'+
  '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
  '<div id="bodyContent">'+
  '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
  'sandstone rock formation in the southern part of the '+
  'Northern Territory, central Australia.'+
  'Heritage Site.</p>'+
  '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
  'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
  '(last visited June 22, 2009).</p>'+
  '</div>'+
  '</div>';

如果我尝试遵循此结构并添加 ,我会得到一张空白照片。谢谢!!

ContentString= '<img src= "photo" alt="url" />'

需要

ContentString= '<img src= "'+photo+'" alt="'+url+'" />'

将字符串的元素与 + 符号(在您的情况下为单引号)之间连接起来。像这样;

ContentString = '<img src="' + photo + '" alt="' + url + '" />';