Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Gmaps4rails中居中标记_Javascript_Ruby On Rails 4_Google Maps Api 3_Gmaps4rails - Fatal编程技术网

Javascript 如何在Gmaps4rails中居中标记

Javascript 如何在Gmaps4rails中居中标记,javascript,ruby-on-rails-4,google-maps-api-3,gmaps4rails,Javascript,Ruby On Rails 4,Google Maps Api 3,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> </di

阅读之后,我仍然无法让标记显示在页面中心

我的代码如下

在视图中

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

目前,页面上的标记位于容器div的一角。如何使标记显示在中心?有没有办法改进视图中的map div


谢谢大家!

你必须知道你想要什么:

// 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();

因此,保留您喜欢的代码,但不要混用,只需

是否需要在centerOn之后设置Zoom?
/* 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%;
}
// 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();