2013-08-20 136 views
1

你好我试图将图像添加到谷歌地图的信息窗口,我的代码是这样的脚本谷歌地图如何添加图片到信息窗口

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文件中添加一些代码,而不是确定什么?

回答

0

使用此,我想这一次在我的应用程序:

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

相反的:

infoWindow: { 
    content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107" 
} 
+0

我在哪里可以添加图像标记,然后你能告诉我一个例子 – user2527785

+0

infoWindow.setContent。?(’“); – Lucifer

+0

循环,公司 795 Park Ave,Suite 120
旧金山,加利福尼亚州94107 – Lucifer

4

你把你的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”。您也可以使用绝对网址。小心混合(双引号)的“和‘(单引号)

+0

非常感谢,我把我的报价混淆了 – user2527785