我正在使用Gmaps4rails gem。我可以在没有Infowindow的情况下显示标记,但在控制器中添加Infowindow后,任何标记都不会出现。如下所示,Infowindow是部分渲染的。
我应该更改代码?提前谢谢。
clinics_controller.rb
@hash = Gmaps4rails.build_markers(@clinics) do |clinic, marker|
marker.lat clinic.latitude
marker.lng clinic.longitude
marker.json({:id => clinic.id})
marker.picture ({
"url" => "/images/red-dot.png",
"width" => 32,
"height" => 32
})
marker.infowindow render_to_string(partial: "map_infowindow", locals: {clinic: clinic})
end
_map_infowindow.html.erb
<h3><%= clinic.name %></h3>
的Javascript
<script type="text/javascript" charset="utf-8">
handler = Gmaps.build('Google');
handler.buildMap({
provider: {
zoom: 15,
center: {lat: 35.765, lng: 139.62}
},
internal: {id: 'map'}},
function(){
markers = handler.addMarkers(<%= raw @hash.to_json %>);
}
);
</script>