javascript Google Maps 如何将图像添加到 InfoWindow
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18333671/
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
Google Maps How to add Image into InfoWindow
提问by user2527785
Hi I am trying to add an image into a google maps infoWindow, my code is like this a script
嗨,我正在尝试将图像添加到谷歌地图信息窗口中,我的代码就像这样一个脚本
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);
});
}
};
}();
Then in my HTML it gets called like this:
然后在我的 HTML 中它被这样调用:
<div class="row-fluid">
<div id="map" class="gmaps margin-bottom-40" style="height:400px;"></div>
</div>
I tried adding an image tag into the script file but it doesn't work, I understand I have to add some code in the html file instead but not sure as to what?
我尝试在脚本文件中添加一个图像标签,但它不起作用,我知道我必须在 html 文件中添加一些代码,但不确定是什么?
采纳答案by Lucifer
Use this, I tried this one in my app:
使用这个,我在我的应用程序中尝试了这个:
infoWindow.setContent(html);
infoWindow.open(map, marker);
Instead of:
代替:
infoWindow: {
content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107"
}
回答by geocodezip
You add your HTML to reference the image in the InfoWindow "content"
您添加 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'>"
}
});
Above assumes the image "myimage.jpg" in the local directory. You can also use an absolute URL. Be careful of mixing " (double quotes) and ' (single quotes).
以上假设本地目录中的图像“myimage.jpg”。您也可以使用绝对 URL。小心混合 " (双引号) 和 ' (单引号)。