开发者

Are there any Simple and Clean Methods to implement Maps (Google or otherwise) in RoR 3?

开发者 https://www.devze.com 2023-01-02 15:00 出处:网络
I\'m looking into building a group work app for my final year project next year. One of the core parts is organising group meetings. I plan to开发者_StackOverflow社区 make this as powerful as possible

I'm looking into building a group work app for my final year project next year. One of the core parts is organising group meetings. I plan to开发者_StackOverflow社区 make this as powerful as possible and adding a map can help get rid of excuses such as "I didn't know where it was".

I have been unable to find any simple solutions to embed maps into my Rails apps so far. An important issue is I need Rails 3 Compatibility.

What are your suggestions? Gems, plugins or even something totally different?


The Geokit gem is what you'll want for doing lat/lng look ups using ips or addresses. It works well from the command line as well, if you want to look up and cache the results before hand.

As far as the map itself is concerned, I just went through this process and it really is just html/javascript that needs to be copied into a view or layout, inserting a loop for marking addresses and just a few variables if you want to set options like zoom level. Just get a static page to work, and turn that into your view really and replace your options with variables just like you would with any other page.

One thing I'll add is that every module (ruby or javascript) seems to refer to latitude and longitude as "lat" and "lng". So I have this ugly mix of long and short names for the same pieces of data that I'll get around to fixing "some day".


addr = CGI.escape(@location.address + ',' + @location.city_name + ',' + @location.state_abbr + ',' + @location.zip_code)

<%= image_tag "http://maps.google.com/maps/api/staticmap?center=#{addr}&zoom=16&size=600x400&markers=color:blue|#{addr}&sensor=false" %>


Fyi, I've just released a new version of gmaps4rails:

https://github.com/apneadiving/Google-Maps-for-Rails

0

精彩评论

暂无评论...
验证码 换一张
取 消