如何使infowindow自动显示为使用Google-Maps-for-Rails打开 [英] How do I make an infowindow automatically display as open with Google-Maps-for-Rails

查看:232
本文介绍了如何使infowindow自动显示为使用Google-Maps-for-Rails打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个地图,其中infowindow框自动显示在页面上的单个标记上,就像 http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html



我试过编写一个回调函数来完成这个任务,但它不适合我。

 <%content_for:scripts do%> 
< script type =text / javascriptcharset =utf-8>
Gmaps.map.callback = function(){
if(Gmaps.map.markers.length == 1){
var marker = Gmaps.map.markers [0];
var infowindow = marker.infowindow;
infowindow.open(Gmaps.map,marker);
}
}
< / script>
<%end%>


解决方案

您的代码几乎是完美的。除了这个:

  infowindow.open(Gmaps.map,marker); 

您应该拥有:

  infowindow.open(Gmaps.map.map,marker); 

确实,Gmaps.map是一个容器,Gmap.map.map是google对象。 p>

我知道这些名字很混乱。对不起。



PS:请务必在您的视图中将此代码置于gmaps调用之下。


I want to display a map with the infowindow box automatically displayed for the single marker on the page, much like http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html

I've tried to code a callback function to accomplish this, but it's just not working for me.

<% content_for :scripts do %>
  <script type="text/javascript" charset="utf-8">
    Gmaps.map.callback = function() {
      if (Gmaps.map.markers.length == 1) {
        var marker = Gmaps.map.markers[0];
        var infowindow = marker.infowindow;
        infowindow.open(Gmaps.map, marker);
      }
    }
  </script>
<% end %>

解决方案

Your code is almost perfect. Except that instead of:

 infowindow.open(Gmaps.map, marker);

You should have:

 infowindow.open(Gmaps.map.map, marker);

Indeed, Gmaps.map is a container, Gmap.map.map is the google object.

I know these names are confusing. Sorry.

PS: be sure to put this code under the gmaps call in your view.

这篇关于如何使infowindow自动显示为使用Google-Maps-for-Rails打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆