Rails Google Maps Plugin 1

Posted by John Wulff Sun, 06 Aug 2006 03:03:00 GMT

I’ve written a Google Maps plugin for Rails. Right now it is fairly simple but it will grow as I need more functionality.

I was going to use the Cartographer plugin but I wanted something a little more tailored to my needs so I decided to create my own. However, looking at the Cartographer code was helpful in overcoming some of the hurdles I encountered (stupid IE).

To install:
$ cd my_rails_app
$ script/plugin install https://secure.near-time.com/svn/plugins/trunk/unbacked_dom_id/
$ script/plugin install https://secure.near-time.com/svn/plugins/trunk/google_maps/
You’ll need to define your API key in your environment.rb
# Signup for a key at http://www.google.com/apis/maps/signup.html
GOOGLE_APPLICATION_ID = "insert key here"
Then, all you have to do is put something like this in a view:
<%
map = GoogleMap.new
map.markers << GoogleMapMarker.new(:map => map, 
                                   :lat => 47.6597, 
                                   :lng => -122.318,
                                   :html => 'My House')
-%>
<%= map.to_html %>
<%= map.div %>

For more examples and info check out the ever-evolving README.

Doesn’t get much easier…

UPDATE: My UnbackedDomId plugin is used in the GoogleMaps plugin. It is now required. The instructions above have been updated. If you’re already up and running, you’ll see breakage until you do this:

$ cd my_rails_app
$ script/plugin install https://secure.near-time.com/svn/plugins/trunk/unbacked_dom_id/

Trackbacks

Use the following link to trackback from your own site:
http://www.johnwulff.com/trackbacks?article_id=rails-google-map-plugin&day=05&month=08&year=2006

Comments

Leave a comment

  1. Avatar
    LinuxDan 9 months later:
    Which of your needs were not being met by cartographer? The link to your README seems to be broken so I couldn't read up on your plugin's features myself.
Comments