1

gmaps4rails を使用しています。私は次のことを達成しようとしています: マップはマーカー付きの場所を示しており、ユーザーは自分の視界をズーム/移動できます。私が望むのは、彼がそうするにつれて、マップの横にあるリストが、現在表示されているすべての場所で動的に更新されることです。コールバック メカニズムと getBounds を使用して、表示されるデータ構造をフィルタリングしようとしましたが、成功しませんでした。どうすればそれについて行くことができますか?

どうもありがとう!ジュリアン

私のコントローラーで:クラスLocationsController <ApplicationController

  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>
4

0 に答える 0