谷歌地图如何将图像添加到InfoWindow中

2024-07-01

您好,我正在尝试将图像添加到谷歌地图信息窗口中,我的代码就像这样的脚本

 var ContactUs = function () {

return {
    //main function to initiate the module
    init: function () {
        var map;
        $(document).ready(function(){
          map = new GMaps({
            div: '#map',
            lat: -13.004333,
            lng: -38.494333,
          });
           var marker = map.addMarker({
                lat: -13.004333,
                lng: -38.494333,
                title: 'Loop, Inc.',
                infoWindow: {
                    content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107"
                }
            });

           marker.infoWindow.open(map, marker);
        });
    }
};

 }();

然后在我的 HTML 中它被这样调用:

  <div class="row-fluid">
     <div id="map" class="gmaps margin-bottom-40" style="height:400px;"></div>
 </div>

我尝试在脚本文件中添加图像标签,但它不起作用,我知道我必须在 html 文件中添加一些代码,但不确定什么?


您添加 HTML 以引用 InfoWindow“内容”中的图像

       var marker = map.addMarker({
            lat: -13.004333,
            lng: -38.494333,
            title: 'Loop, Inc.',
            infoWindow: {
                content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107<br><img src='myimage.jpg' alt='image in infowindow'>"
            }
        });

上面假设图像“myimage.jpg”位于本地目录中。您还可以使用绝对 URL。请小心混合使用“(双引号)和'(单引号)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

谷歌地图如何将图像添加到InfoWindow中 的相关文章