Skip to content

Navigation Menu

Sign up
apneadiving edited this page Mar 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
 {"strokeColor": "#000"},
 //other hashes simply contain longitude and latitude
 {"longitude": -80.190262, "latitude": 25.774252},
 {"longitude": -66.118292, "latitude": 18.466465},
 {"longitude": -64.75737, "latitude": 32.321384}
 ],
 //second polyline
 [
 // the first hash contains positions so it will use default display options
 {"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

AltStyle によって変換されたページ (->オリジナル) /