0
我一直在github上关注gmaps4rails教程,但我不了解如何自定义infowindow。我有一个收集实习数据的数据库,包括地点,姓名,公司和说明。标记出现在地图上的正确位置,但我只能在需要显示名称或描述或公司时才能显示所有这些标记。Rails:使用gmaps4rails自定义infowindow
我是新来的rails,并不完全理解我需要更新以允许所有这些属性出现在infowindow中。我附上我的代码如下:
实习模式:
class Internship < ApplicationRecord
geocoded_by :address
after_validation :geocode
end
实习查看:
<script src="//maps.google.com/maps/api/js?key=AIzaSyBj4qLUeW291Z5WvVOwzseQONRBGCnA8ds"></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->
<div style='width: 800px;'>
<div id="map" style='width: 1100px; height: 600px'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
实习控制器:
def index
@internships = Internship.all
@hash = Gmaps4rails.build_markers(@internships) do |internship, marker|
marker.lat internship.latitude
marker.lng internship.longitude
marker.infowindow internship.description
end
end
任何帮助我能是非常感谢!