Google 地图、Ruby on Rails、使用一个标记的缩放级别
我正在通过 apneadiving / Google-Maps-for-Rails 添加谷歌地图支持(感谢很棒的 gem),
但是我发现了一个小故障,这很可能是我的错。
当有多个标记时,auto_zoom 效果很好。然而,当只有一个标记时,它会放大到最大级别,这不太漂亮。
“zoom”仅在 auto_zoom 为 false 时才起作用,所以这不是我想要的。
因此,您可以使用“maxZoom”,但现在用户无法手动放大到超出该点,这不是我想要的。
有办法解决这个问题吗?我的解释有道理吗?这是 Google 地图 API 的限制吗?
谢谢...
I am adding google maps support with apneadiving / Google-Maps-for-Rails (thanks awesome gem)
I am finding one slight glitch, however, which very likely is my fault.
auto_zoom works great when there are multiple markers. However, when there is only one marker it is zoomed in to the max level which is not pretty.
"zoom" will only work when auto_zoom is false, so that's not what I want.
So therefore you could use "maxZoom" but now users cannot zoom in manually beyond that point which is not what I want.
Is there a way around this? Is my explanation making sense? Is this a limitation of Google Maps API?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此行为是由于 google 地图 API 中的
auto_zoom
内置函数造成的。解决此问题的一种解决方法是在
gmaps
方法中将其设置为false
:然后使用
gmaps4rails_callback
来满足您的需求(请务必版本至少为 0.7.9)This behavior is due to the
auto_zoom
built-in function in the google maps api.One work around to this is to set it to
false
in thegmaps
method:And then use the
gmaps4rails_callback
to fit your needs (be sure to have at least version 0.7.9)我以一种稍微不同的方式实现了这一点,因为我知道我的地图上只会有一个标记。我对 Rails 比较陌生,但在你看来,这种方法比使用 JS 感觉更“干净”一些。
我的模型中存储了 lat 和 lng(在创建时由 geokit 编码),因此在我看来执行了以下操作:
@markers 是我由 blah.to_gmaps4rails 创建的 JSON,“listing”是我的模型。
I achieved this in a slightly different way as I know that I'll only ever have one marker on my map. I'm relatively new to rails, but this method feels a bit "cleaner" than using JS in your view.
I've got lat and lng stored in my model (encoded by geokit at time of creation), so did the following in my view:
@markers is my JSON created by blah.to_gmaps4rails, and "listing" is my model.
谢谢这对我有帮助...
{"auto_zoom" => false, "zoom" => 15, "center_latitude" => @listing.lat, "center_longitude" => @listing.lng },
"markers" => {"data" => @markers }
})
%>
thanks this helped me...
{"auto_zoom" => false, "zoom" => 15, "center_latitude" => @listing.lat, "center_longitude" => @listing.lng },
"markers" => {"data" => @markers }
})
%>