Wednesday, December 6, 2006

Cartographer Google Maps plugin

Cartographer

Ruby on Rails :: Google Maps plugin

Installation

Install as a plugin! From your rails application root, run


script/plugin install -x svn://cartographer.rubyforge.org/
trunk/vendor/plugins/cartographer
Or, install from svn
svn co svn://rubyforge.org//var/svn/cartographer/trunk 

Usage

First you need to sign up for an API key

Then, put your API key into the vendor/plugins/cartographer/lib/keys.rb file.

Open up your layout template (if you're using one) and

insert this code into the HEAD section:

<head>
<%= gmaps_header %>
...
</head>

Now, in your controller* define your map and set up some markers.

def map
@map = Cartographer::Map.new( :name => 'mymap', :width =>
300, :center => [-110,33], :debug => true)
@map.markers << Cartographer::Marker.new( :position =>
[-110,33], :info_window => 'Clicky clicky!!', :map => @map )
end

* Realistically this can also be in your view, but it's a bit naughty of you to consider bending MVC!

Finally, render the map in your view.


<%= @map.to_html >

If you view the source to this page, you'll see what the above lines of code look like in
the rendered code (below this point). You can remove the :debug => true if you don't want commenting (it will compress
the code a little, too)

Requirements

Because Cartographer is a plugin, you need to be running rails 0.14.3 or up (1.0 is great..)

You can easily use the code in other ruby-based frameworks quite easily, because there's nothing
actually tied to Rails.

If you're using an old version of cartographer, or old version of rails, we strongly recommend
you upgrade; however, check out the subversion repository, because we've tagged the old version
for you old-schoolers.

More information

We just underwent a complete changeover of code, so the API code still needs to catch up. Until then,
you're smart, you can more than likely understand what's going on from reading the plugin source.

Cartographer was written by Robert Bousquet,
Courtenay Gasking and Phil Hagelberg
with some additional code by Jeremy Hubert and
Bryan Wood.



source courtesy: Cartographer

1 comment:

Unknown said...

Hi
This is Ramesh.S, from citrisys solutions , chennai. i'm working on ruby on rails and i want to keep in touch with other ror experts. i do have a blog of my own to view that click here and comment on my postings
http://ramesh-rubyonrails.blogspot.com/

Pay Pal

Sign up for PayPal and start accepting credit card payments instantly.

Ruby Corner

Earn Money