How to Configure the Google Maps for Rails Map config file?
I'm using the GM4Rails Gem.
I'm very n开发者_如何学运维ewbie to Rails and I'm trying to find the config file so I can get a HYBRID Google Maps instead of the ROADMAP.
I couldn't find the file: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map
Is there anyway I can change the config?
You have to know that:
<%= gmaps4rails(@json) %>
is a shortcut for:
<%= gmaps("map_options" => { "auto_adjust" => true},
"markers" => { "data" => @json })
%>
When you need to pass additional options, you have to use the gmaps
helper. In your case:
<%= gmaps("map_options" => { "auto_adjust" => true, "type" => "HYBRID" },
"markers" => { "data" => @json })
%>
As you saw many more options are available.
If you are calling the Gmaps.loadMaps();
function directly, use:
search_map = new Gmaps4RailsGoogle();
Gmaps.search_map = search_map;
search_map.map_options.raw.streetViewControl = false; // yes, raw
// more options
search_map.map_options.id = "search_map";
search_map.map_options.maxZoom = 14;
search_map.map_options.zoom = 12;
Gmaps.loadMaps();
I am not too sure about the rest of the code (it's from an old codebase), but the line you are looking for is search_map.map_options.raw.streetViewControl = false;
So to display a map you use something like the code below:
<%= gmaps({
"map_options" => {"container_id" => "connections_map_container", "auto_adjust" => "true", "bounds" => '[{"lat": 0, "lng": 0 }, {"lat": 80 , "lng": 100 }]'},
... #add here data you want to display
})
%>
This is where you pass in your map options, so anywhere on that line you would insert "type" => "HYBRID"
So the modified example would look like
<%= gmaps({
"map_options" => {"container_id" => "connections_map_container", "auto_adjust" => "true", "bounds" => '[{"lat": 0, "lng": 0 }, {"lat": 80 , "lng": 100 }]'}, "type" => "HYBRID"
... #add here data you want to display
})
%>
精彩评论