0
在地面上使用gmaps4rails進行地圖功能:在控制器中結合變量
這個想法是在地圖上顯示房子的標記加上多個景點。
我有這段代碼;
控制器:
@house = House.friendly.find(params[:id])
@location = @house.location
@sights_markers = Location.where("category = 'sights'")
records = [@location, @sights_markers].compact
@hash = Gmaps4rails.build_markers(records) do |location, marker|
marker.lat location.latitude
marker.lng location.longitude
end
觀點:
<div id="map" style='width: 100%; height: 500px; margin-top: 10px; margin-bottom: 20px;' ></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>
我得到發現 「緯度」
我在做什麼錯了一個錯誤message..no方法?
什麼是你的位置表的方案?它有'緯度'字段嗎? – DiegoSalazar 2014-09-29 17:05:33