How to use multiple maps on single page?
I want to use multipul map on single page. Here is.
# example.html.erb
<%= gmaps4rails(@json1) %开发者_Go百科>
<%= gmaps4rails(@json2) %>
Map can't display, all map white out ... Please help if anyone knows the solution.
Thanks.
There has been some improvements to how this is done.
Now it is more like this:
<%= 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 ) %>
Check out https://github.com/apneadiving/Google-Maps-for-Rails/wiki/%28Multiple%29-Maps
EDIT:
Since v1.0.0
, it's really simple to add multiple maps on the same page, see wiki.
It's not very straight as I didn't need this but it could be done quite easily.
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 %>
精彩评论