您好,我正在尝试将图像添加到 google maps infoWindow 中,我的代码就像这样一个脚本
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 以引用信息窗口“内容”中的图像
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。小心混用 "(双引号)和 '(单引号)。
关于javascript - Google Maps 如何将图像添加到 InfoWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18333671/