2

我想在单页上使用 multipul 地图。这是。

# example.html.erb
<%= gmaps4rails(@json1) %>
<%= gmaps4rails(@json2) %>

地图无法显示,所有地图都变白了...如果有人知道解决方案,请提供帮助。

谢谢。

4

2 回答 2

4

对此进行了一些改进。

现在更像这样:

<%= gmaps(:markers     => {:data => @json1 },
          :map_options => { :auto_adjust => true },
          :last_map    => false) %>
<%= gmaps(:markers     => @json2 },
          :map_options => { :id => "second_map", :center_on_user => true, :zoom => 5 },
          :scripts     => :none ) %>

查看https://github.com/apneadiving/Google-Maps-for-Rails/wiki/%28Multiple%29-Maps

于 2011-09-01T00:18:26.197 回答
1

编辑:

因为v1.0.0,在同一页面上添加多个地图非常简单,请参阅 wiki


它不是很直接,因为我不需要它,但它可以很容易地完成。

first map here, it triggers the load of the necessary js files.
<%= gmaps4rails (@json1) %>

/the empty divs for second map (beware to provide the proper css)
<div id="second_container"> 
  <div id="second_map"></div>
</div>

<% content_for :scripts do %>
<script>

var counter = 0;

Gmaps4Rails.callback = function() {
  if (counter == 0){
    counter += 1;
    <%=   { "map_options" => {  
                          "container_id" => "second_container", "id" => "second_map",
                          "type" => "SATELLITE", "center_longitude" => 180, "zoom" => 3, "auto_adjust" => true 
                          },
            "markers"     => { "data" => @json2 }
          }.to_gmaps4rails(true).html_safe
    %>
   }
};
<script>
<% end %>
于 2011-08-03T09:55:27.650 回答