用于谷歌地图集成的 Ruby on rails gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/903457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby on rails gem for google map integration
提问by Konstantinos
I would like to ask which is the best solution for integrating google maps into ruby on rails apps. Is a specific gem worth it or should we write our own views for it?
我想问一下哪个是将谷歌地图集成到 ruby on rails 应用程序的最佳解决方案。一个特定的宝石是否值得,还是我们应该为它写下我们自己的观点?
Thanks for any input.
感谢您提供任何意见。
采纳答案by Kevin
I've used the YM4R, Georuby and spatial adapter gems with good results before. see this description.
我之前使用过 YM4R、Geruby 和空间适配器 gem,效果很好。请参阅此说明。
回答by apneadiving
Fyi, I've finished a stable release of gmaps4rails.
仅供参考,我已经完成了 gmaps4rails 的稳定版本。
回答by Voldy
If your requirements are only to show google map of specific region, possibly with some markers, you can use Google Maps Static Image API, for example:
如果您的要求只是显示特定区域的谷歌地图,可能带有一些标记,您可以使用谷歌地图静态图像 API,例如:
<img src="http://maps.google.com/maps/api/staticmap?size=255x255&maptype=roadmap&sensor=false&markers=color:blue|label:A|Chicago,IL&markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom"></img>
The result is:
结果是:


Here is a good articleon subject. Also it's possible to specify geo location with latitude and longitude on markers:
这是一篇关于主题的好文章。还可以在标记上使用纬度和经度指定地理位置:
markers=color:pink|label:A|55.783041, -137.500994
So in Rails you can use, for example, image_tagwith google map image path helper:
因此,在 Rails 中,您可以使用,例如,image_tag谷歌地图图像路径助手:
= image_tag google_map_image_path, :alt => "Google Map"
回答by Sivan
As of November 2012,the best gem for google map integration which I have found is geocoder
It provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
截至 2012 年 11 月,我发现的谷歌地图集成的最佳宝石是地理编码器,
它提供对象地理编码(按街道或 IP 地址)、反向地理编码(街道地址的坐标)、ActiveRecord 和 Mongoid 的距离查询、结果缓存和更多的。专为 Rails 设计,但也适用于 Sinatra 和其他 Rack 框架。
You can get a railscaststoo.
你也可以得到一个railscasts。
回答by Dariya L.
GoogleMapsgem is a nice one. It adds all basic JS scripts but a full-functional dynamic map can't be done without JS coding anyway.
GoogleMapsgem 是一个不错的选择。它添加了所有基本的 JS 脚本,但无论如何,没有 JS 编码就无法完成功能齐全的动态地图。
There are also JS plugins, the most attractive of them are gmap3, Maplace.Js and gmaps.js.
还有JS插件,其中最吸引人的是gmap3、Maplace.Js和gmaps.js。
Gems and plugins allow saving time on basic things but using them imposes some restrictions. For example, if Google makes changes in its Maps API, you have to wait for an updated version of the gem or plugin or integrate manually.
Gems 和插件允许在基本事物上节省时间,但使用它们会施加一些限制。例如,如果 Google 对其 Maps API 进行了更改,则您必须等待 gem 或插件的更新版本或手动集成。
In fact, there is no major difficulty in integrating Google Maps into Rails app and IMHO it makes sence to do it without gems.
事实上,将 Google Maps 集成到 Rails 应用程序中并没有什么大的困难,恕我直言,没有 gem 就可以做到这一点。
See this article for a detailed walkthrough on integrating Google Maps into ruby on rails apps: How to Integrate Google Maps into Ruby on Rails App.
有关将 Google 地图集成到 ruby on Rails 应用程序的详细演练,请参阅本文:如何将 Google 地图集成到 Ruby on Rails 应用程序中。

