집과 도시/광경을 하나의지도에 표시하고 싶습니다.하나의지도에 모델을 곱하십시오.
내 컨트롤러 :
@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