2

this answer을 읽은 후 페이지 중앙에 마커를 표시하는 데 여전히 문제가 있습니다.Gmaps4rails의 가운데 표시 방법

내 코드는 다음과 같습니다. 컨트롤러

def edit 
    @user = current_user 
    @hash = Gmaps4rails.build_markers(@user) do |u, marker| 
    marker.lat u.latitude 
    marker.lng u.longitude 
    marker.infowindow u.name 
    end 
end 

CSS

/* Flexible iFrame */ 

.Flexible-container { 
position: relative; 
padding-bottom: 56.25%; 
height: 0; 
overflow: hidden; 
} 

.Flexible-container iframe, 
.Flexible-container object, 
.Flexible-container embed { 
position: absolute; 
top: 0; 
left: 0; 
width: 100%; 
height: 100%; 
} 

에서보기

<div class="Flexible-container"> 
<!--Google Maps Div--> 
      <div id="map" style='width: 425; height: 425px;' frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></div> 
</div> 
      <!-- End of Responsive iFrame --> 
      <script type="text/javascript"> 
      handler = Gmaps.build('Google'); 
      handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
      markers = handler.addMarkers(<%=raw @hash.to_json %>); 
      handler.map.centerOn(markers[0]); 
      handler.bounds.extendWith(markers); 
      handler.fitMapToBounds(); 
      handler.map.serviceObject.setZoom(16); 
      }); 
      </script> 

에서

현재 페이지에 마커가 컨테이너 사업부의 코너에있다. 마커가 가운데에 표시되도록하려면 어떻게해야합니까? 보기에서 내지도 div를 향상시킬 수있는 방법이 있습니까?

감사합니다.

답변

9

당신은 당신이 원하는 것을 알고있다 :

// to center on a marker 
handler.map.centerOn(markers[0]); 
// to set the map zoom 
handler.getMap().setZoom(16); 


// to center the map AND adjust zoom to see ALL markers 
handler.bounds.extendWith(markers); 
handler.fitMapToBounds(); 

그래서 당신이 선호하는 코드를 유지하지만 혼합 해달라고, 단순히

+0

가 centerOn 후 setZoom하는 것이 필요하다? – Aakanksha