Cartographer Plugin for Rails 3/Google Maps 3 support

Maps are integral part of any application with spatial data. In the past, I’ve utilized Google Maps interface with the YM4R plugin. It was always a little cumbersome in spots but did the trick. There was also the restriction of having to register a key for use in each API call.

But what if you wanted to take advantage of great version 3 features like Street View or Driving Directions? You’d be a little wanting as the YM4R plugin only supported V2 of the API.

Enter the cartographer plugin ( This plugin provides both v2 and v3 API support, as well as clean Rails 3 integration. I feel the code is a little cleaner too. Here’s a brief tutorial of how to add it to your application.


Either install the plugin for via:

rails plugin install git://


git clone git:// vendor/plugins/cartographer


Next, you will need to add some basic code to your controller to create the map object. I prefer to create a helper to do this as it will be used frequently.

module GoogleMapsHelper  
  def map_init'map')    
    @map.icons <<  

I typically add code to the model to be mapped to create the geomarker and info window.

class Site < ActiveRecord::Base  
  def geomarker> 'site', :marker_type => "Building", :position => ll)  

  def ll    
    Array.[]( location.y, location.x )  

From within the controller, call the initialization method and add a marker.

class HousesController < ApplicationController  
  include GoogleMapsHelper
  def index        
    if @site      
      @map.markers << @site.geomarker    
  # and more code...  

Finally to your view, add the necessary code to render the map to a div with the specified id.

<div id='map'>  
  <%= raw %>    
  <%= raw @map.to_html %>  

And that’s it! Pretty simple and very clean in my estimation. I’m now not dreading the upgrade of my mappable applications to Google Maps v3.

  1. i am new to rails….
    where to specify the API-Key….? please give me a detailed information

  2. i need a example for Rails 3.2.9

  3. I wouldn’t suggest using this plugin anymore for a few reasons. For starters, plugins in the vendor directory are going away. Instead I would recommend using the gmaps4rails gem ( instead. I’m not sure whether it warrants me writing a tutorial here, but I could if there was some demand.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: