我想在一張地圖上顯示房子和城市/景點。在一張地圖上乘以模型?
我的控制器:
@house = House.friendly.find(params[:id])
@city = City.find(1)
@location = @house.location
@location1 = @city.location
records = @location || @location1
@hash = Gmaps4rails.build_markers(records) do |location, marker|
marker.lat location.latitude
marker.lng location.longitude
end
查看
<header>
<h3 class='text'>
<%= t('navigation.sub_nav.location') %>
</h3>
<div id="map" style='width: 100%; height: 400px; margin-top: 10px;' ></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();
handler.getMap().setZoom(7);
});
</script>
我只顯示在地圖上,而不是城市的房子。我在這裏做錯了什麼?
您可能需要'records = @location + @ location1' – Santhosh 2014-09-28 07:41:42