Ruby on rails 使用Gmaps4rails,我如何显示地图视图中当前可见的位置列表?
我正在使用gmaps4rails。我试图做到以下几点:地图用标记显示位置,用户可以根据自己的意愿缩放/移动他的视窗。我想要的是,当他这样做的时候,地图旁边的列表应该动态地更新当前可见的所有位置。 我尝试使用回调机制和getBounds来过滤可见数据结构,但没有成功。 我该怎么做呢 非常感谢! 朱利安 在我的控制器中:类位置控制器<应用程序控制器Ruby on rails 使用Gmaps4rails,我如何显示地图视图中当前可见的位置列表?,ruby-on-rails,gmaps4rails,Ruby On Rails,Gmaps4rails,我正在使用gmaps4rails。我试图做到以下几点:地图用标记显示位置,用户可以根据自己的意愿缩放/移动他的视窗。我想要的是,当他这样做的时候,地图旁边的列表应该动态地更新当前可见的所有位置。 我尝试使用回调机制和getBounds来过滤可见数据结构,但没有成功。 我该怎么做呢 非常感谢! 朱利安 在我的控制器中:类位置控制器@json,“options”=>{“list\u container”=>“markers\u list”,“do\u clustering”=>true})%> 名称
def index
if (params[:sw_y] && params[:sw_x] && params[:ne_y] && params[:ne_x])
bounds = [ [params[:sw_x].to_f, params[:sw_y].to_f],
[params[:ne_x].to_f, params[:ne_y].to_f] ]
@locations_within_bounds = Location.within_bounds(bounds)
else
@locations_within_bounds = Location.all
end
@locations = Location.all
@json = Location.all.to_gmaps4rails
在我看来:
<%= gmaps("markers" => {"data" => @json, "options" => {"list_container" => "markers_list", "do_clustering" => true } } ) %>
<table>
<tr>
<th>Name</th>
<th>Address</th>
<th>Longitude</th>
<th>Latitude</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @locations_within_bounds.each do |location| %>
<tr>
<td><%= location.name %></td>
<td><%= location.address %></td>
<td><%= location.longitude %></td>
<td><%= location.latitude %></td>
</tr>
<% end %>
</table>
{“data”=>@json,“options”=>{“list\u container”=>“markers\u list”,“do\u clustering”=>true})%>
名称
地址
经度
纬度
这个想法很好,我想实现失败了,这不能用gmaps4rails实现吗?我确实在网络上的其他地方看到过这样的行为,因此我想知道如何做到这一点。您的实现在某个地方失败了。有代码吗?在上面的问题中添加了我的代码片段