2

После прочтения this answer у меня все еще возникают проблемы с отображением маркера в центре страницы.Как маркер центра в Gmaps4rails

Мой код выглядит следующим образом;

По мнению

<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> 

В контроллере

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 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

Нужно ли setZoom после centerOn? – Aakanksha

Смежные вопросы