gpt4 book ai didi

ruby-on-rails - Gmaps4rails V2 - 更改默认缩放

转载 作者:行者123 更新时间:2023-12-03 11:19:35 25 4
gpt4 key购买 nike

我是一个完整的菜鸟,正在构建我的第一个 Rails 应用程序。我成功实现了 Google-maps-for-rails V2,使用 youtube 上的 apneadiving 教程:http://www.youtube.com/watch?v=R0l-7en3dUw&feature=youtu.be

我的问题是,对于我的每张 map ,我只显示一个标记,本地图加载时,它会调整为完全缩放。

环顾四周,Gmaps4rails 的早期版本似乎有很多解决方案,但是对于 V2,并通过 javascript 创建 map ,我似乎找不到有效的解决方案。

作为引用,我的代码如下:

看法:

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

Controller :
def show
@pins = Pin.find(params[:id])
@hash = Gmaps4rails.build_markers(@pins) do |pin, marker|
marker.lat pin.latitude
marker.lng pin.longitude
end
end

我尝试使用:gmap.setzoom(12) 通过控制台进行更改,正如一些帖子所建议的那样,但没有任何运气。

任何帮助深表感谢

对我有用的答案:将 View 更改为:
  <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(12);
}); </script>

谢谢您的帮助!

最佳答案

消除:

handler.fitMapToBounds();

用。。。来代替:
handler.getMap().setZoom(yourValue);

关于ruby-on-rails - Gmaps4rails V2 - 更改默认缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19918942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com