我正在使用 GM4Rails Gem。
我是 Rails 的新手,我正在尝试查找配置文件,以便获得 HYBRID Google Maps 而不是 ROADMAP。
我找不到文件:https ://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map
无论如何我可以更改配置吗?
我正在使用 GM4Rails Gem。
我是 Rails 的新手,我正在尝试查找配置文件,以便获得 HYBRID Google Maps 而不是 ROADMAP。
我找不到文件:https ://github.com/apneadiving/Google-Maps-for-Rails/wiki/Map
无论如何我可以更改配置吗?
你必须知道:
<%= gmaps4rails(@json) %>
是一个快捷方式:
<%= gmaps("map_options" => { "auto_adjust" => true},
"markers" => { "data" => @json })
%>
当您需要传递其他选项时,您必须使用gmaps
helper。在你的情况下:
<%= gmaps("map_options" => { "auto_adjust" => true, "type" => "HYBRID" },
"markers" => { "data" => @json })
%>
如您所见,还有更多选项可用。
如果您Gmaps.loadMaps();
直接调用该函数,请使用:
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();
我不太确定其余代码(它来自旧代码库),但您正在寻找的行是search_map.map_options.raw.streetViewControl = false;
因此,要显示地图,您可以使用以下代码:
<%= 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
})
%>
这是您传递地图选项的地方,因此您可以在该行的任何位置插入"type" => "HYBRID"
所以修改后的例子看起来像
<%= 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
})
%>