Skip to content
apneadiving edited this page Apr 9, 2011 · 6 revisions

Data to provide

Valid json should be like:

[
 //first element of the array, describing the first polyline
 [
 //first element of the polyline can optionally contain customization
 {"longitude": -80.190262, "latitude": 25.774252, "strokeColor": "#000"},
 //other hashes simply contain longitude and latitude
 {"longitude": -66.118292, "latitude": 18.466465},
 {"longitude": -64.75737, "latitude": 32.321384}
 ],
 //second polyline
 [
 //no customization in the first hash => all defaults will be applied to display this polyline
 {"longitude":   0, "latitude":   0},
 {"longitude":  10, "latitude":  10},
 {"longitude": -10, "latitude": -10}
 ]
]

Default display configuration:

strokeColor: "#FF0000",
strokeOpacity: 1,
strokeWeight: 2,

Display Polylines

<%= gmaps({
       "polylines"    => { "data" => @polylines_json }
     })
 %>

Change default configuration for polylines

Simply pass options you want to override in a hash.

<%= gmaps({
       "polylines"    => { "data" => @polylines    , "options" => { "strokeColor" => "#000" } }
     })
 %>

Display data from Gmaps4rails.direction

<%# @traj = User.destination({"from" => "Nice", "to" => "Paris"}, {"language" => "fr", "waypoints" => ["Toulon","Toulouse", "Lorient", "Bourges", "Strasbourg", "Namur"] }, "pretty") %> <%# @traj.each do |traj| %> <%#= raw traj["polylines"] + "," %> <%# end %>

Clone this wiki locally