我的目标是添加圆圈代替标记,以显示工具模型中每个工具位置的一般区域。我能够根据 SO 上的其他答案添加圈子,但是使用以下代码我在这个问题的标题中得到了错误。
在我的 Controller 中:
def index
@tools = Tool.all
@json=Tool.all.to_gmaps4rails
@circles = Tool.all{|t| {:longitude => t.longitude, :latitude => t.latitude, :radius =>"1000" }}.to_json
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tools }
end
end
在我的 View 文件中:
<%= gmaps({ "markers" => {"data" => @circles}, "circles" => { "data" => @circles} } ) %>
JavaScript 错误将我定向到 gmaps4rails.googlemaps.js 文件中的第 401 行:
this.boundsObject.extend(circle.serviceObject.getBounds().getNorthEast());
有什么想法吗?
最佳答案
在 this.boundsObject.extend(circle.serviceObject.getBounds().getNorthEast());
并打印我们的圆圈
如果我没记错的话@circle in rails 格式不正确
@circles = Tool.map{|t| {:longitude => t.longitude, :latitude => t.latitude, :radius =>"1000" }}.to_json
应该是map而不是all来映射所有数组并在json中打印出来
关于javascript - 将圆圈添加到 gmaps4rails 时,出现错误 : TypeError: 'undefined' is not an object (evaluating 'circle.serviceObject.getBounds' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13963140/