Ruby noob here. Trying to display a list of points as a polygon on a google map using the gmaps4rails gem (awesome gem by the way). Any suggestions based on code sample be
I passed their base tutorial (from screen cast) and markers works fine. But I had problem with polylines (as you with polygons). At the end I resolved my problem (it can help you with polygons). So, view is the same as they gave :
<%= gmaps({
"polylines" => { "data" => @bemap_polylines }
})
%>
The model is also the same as their.
class Character < ActiveRecord::Base
belongs_to :bemap
acts_as_gmappable
def gmaps4rails_address
#describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
address
logger.info address
end
end
So, the main problem was into controller. Here is mine :
def show
@bemap = Bemap.find(params[:id])
@bemap_polylines = []
@bemap_characters = []
@bemap.characters.each do |v|
@bemap_characters << { :lng => v[:longitude], :lat => v[:latitude]}
end
@bemap_polylines << @bemap_characters
@bemap_polylines = @bemap_polylines.to_json
respond_to do |format|
format.html # show.html.erb
format.json { render json: @bemap }
end
end