Skip to content
apneadiving edited this page Sep 15, 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
 {"lng": -80.190262, "lat": 25.774252, "strokeColor": "#000"},
 //other hashes simply contain longitude and lat
 {"lng": -66.118292, "lat": 18.466465},
 {"lng": -64.75737, "lat": 32.321384}
 ],
 //second polyline
 [
 //no customization in the first hash => all defaults will be applied to display this polyline
 {"lng":   0, "lat":   0},
 {"lng":  10, "lat":  10},
 {"lng": -10, "lat": -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 %>