forked from apneadiving/Google-Maps-for-Rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Controller
matiaswilliams edited this page Jul 3, 2012
·
12 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
Note - Make sure you are serving up the width and height parameters as type int rather than string when using custom markers. Otherwise you run into issues with tiling issues in newer versions of the gmaps api (see: https://github.com/apneadiving/Google-Maps-for-Rails/issues/183).