1

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:

  <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?

4

2 回答 2

4

您添加 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。小心混合使用 "(双引号)和 '(单引号)。

于 2013-08-20T12:34:29.780 回答
0

使用这个,我在我的应用程序中尝试了这个:

infoWindow.setContent(html);
infoWindow.open(map, marker);

代替:

infoWindow: {
    content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107"
}
于 2013-08-20T11:28:53.063 回答