地理编码器按英里和地址搜索

时间:2015-10-01 13:49:36

标签: ruby-on-rails geocoding google-geocoder geocode

我按照此示例http://asciicasts.com/episodes/273-geocoder进行地理编码。任何人都知道我怎么能动态地通过里程而不是在10英里附近静态?因此它将有两个搜索框,一个用于输入英里,另一个用于输入地址。感谢

controller.rb

yourDivClass {
    opacity: 0;
    -webkit-transition-delay: 2s; /* Safari */
    transition-delay: 2s;
}

yourDivClass:hover {
    opacity: 1;
    transition: 0s ease all;
}

index.html.erb

def index  
  if params[:search].present?  
    @locations = Location.near(params[:search], 50, ↵  
      :order => :distance)  
  else  
    @locations = Location.all  
  end  
end  

1 个答案:

答案 0 :(得分:0)

您可以将额外的参数传递给show视图并应用它:

<% for location in @location.nearbys(params[:nearbys].to_i) %> // do not forget check if params[:nearbys] exists and it's an integer

更新show视图的所有链接:

<li><%= link_to location.address, location_path(location, nearby: 15) %> ↵  
(<%= location.distance.round(2) %> miles)</li>