【问题标题】:How to display a selected location along with all other locations using gmaps4rails?如何使用 gmaps4rails 显示选定位置以及所有其他位置?
【发布时间】:2011-12-12 20:49:35
【问题描述】:

我试图弄清楚为什么当我有一张地图显示地图位置的控制器 json 字符串时,当我单击信息框并转到特定的 id 页面时,我无法缩放到特定的 id 位置,并保留其余部分地图上的位置。例如:

显示来自 places_controller 的所有点的地图:

def index
 @json = Places.all.to_gmaps4rails
end

显示自身的单个 id 页面:

def show
 @json = Places.find(params[:id]).to_gmaps4rails
end

我希望 .find(params[:id]).to_gmaps4rails 包含 .all 位置,但以 :id 位置为中心。

ps- 索引地图是 geoLocated 并以用户为中心,而显示位置仅以 1 个标记条目为中心。

谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 gmaps4rails rails-3.1


    【解决方案1】:

    我会这样做:

    def show
      @json   = Places.all.to_gmaps4rails
      @center = Places.find(params[:id])
    end
    

    并且在视图中:

    <%= gmaps( :map_options => { :center_latitude => @center.latitude, :center_longitude => @center.longitude, :zoom => 6 },
               :markers     => { :data => @json } 
             ) %>
    

    【讨论】:

    • 这行得通,我唯一需要改变的是:auto_adjust => true,TO :auto_adjust => false。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    相关资源
    最近更新 更多