【问题标题】:gmaps4rails enable clusteringgmaps4rails 启用集群
【发布时间】:2015-12-28 17:22:38
【问题描述】:

如何启用集群而不是显示集群的标记?例如:https://www.police.uk/metropolitan/00BK17N/crime/

users_controller

class UsersController < ApplicationController
  def index
    @users = User.all
    @hash = Gmaps4rails.build_markers(@users) do |user, marker|
      marker.lat user.latitude
      marker.lng user.longitude
      marker.infowindow user.description
    end
  end
end

index.html.erb

<div id="map-container">
  <div id="map-canvas"></div>
</div>

<script>
$(document).ready(function(){
  handler = Gmaps.build('Google');
  handler.buildMap({ provider: {}, internal: {id: 'map-canvas'}}, function(){
    markers = handler.addMarkers(<%=raw @hash.to_json %>)
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds(markers);
    if(navigator.geolocation)
      navigator.geolocation.getCurrentPosition;
  });
});
</script>

感谢您的帮助

【问题讨论】:

    标签: ruby-on-rails google-maps-api-3 google-maps-markers


    【解决方案1】:

    你试过了吗? https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Markers#displaying-your-markers

    只需传递 do_clustering => true 即可启用它。默认为假。 示例:

    <%= gmaps("markers" => { "data" => @markers, "options" => { "do_clustering" => true } }) %>
    

    【讨论】:

    • 我得到了 #:0x007ff7b929a898> 的未定义方法 `gmaps'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 2015-02-24
    相关资源
    最近更新 更多