Skip to content
apneadiving edited this page Jan 20, 2012 · 16 revisions

Since 1.2.0, you can pass your maps params almost entirely from controller.

That's really useful when it comes to use partials as infowindows and I extended this to the other features.

From 1.4.0, no need to escape characters anymore as Rails to_json will do it for you behind the scene.

Previously, you could just add extra content to the json created:

@json = User.all.to_gmaps4rails do |user, marker|
  "\"id\": #{user.id}"
end

Now, do:

@json = User.all.to_gmaps4rails do |user, marker|
  marker.json "\"id\": #{user.id}, \"foo\": #{user.bar}"
end

Or even better:

@json = User.all.to_gmaps4rails do |user, marker|
  marker.json({ :id => user.id, :foo => user.bar })
end

Here is an example which speaks for itself:

@json = User.all.to_gmaps4rails do |user, marker|
  marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user})
  marker.picture({
                  :picture => "http://www.blankdots.com/img/github-32x32.png",
                  :width   => "32",
                  :height  => "32"
                 })
  marker.title   "i'm the title"
  marker.sidebar "i'm the sidebar"
  marker.json    { :id => user.id, :foo => "bar" }
end

Clone this wiki locally