简体   繁体   English

Rails Geocoder gem显示结果

[英]Rails geocoder gem show results

I'm using the geocoder gem in order to set the longitude and latitude from the address: 我正在使用geocoder gem ,以便从地址设置longitudelatitude

 class Ub < ApplicationRecord

  geocoded_by :full_address
  after_validation :geocode, if: ->(obj){ obj.full_address.present? }

  def full_address
    [street, city, state, zip_code, country].join(",")
  end
end

end search: 结束搜索:

class SearchController < ApplicationController

  def search
    if params[:search].present?
      location_info = request.location
      @ubs = Ub.near([location_info.latitude, location_info.longitude], 5, :order => :distance)
    else
      @ubs = []
    end
  end

Without more information on what the latitude/longitude values of your items are, it's tough to say for sure, but what jumps out at me from your query is this: 没有关于您的items的纬度/经度值的更多信息,很难确定地说,但是从您的查询中跳出来的是:

WHERE (items.latitude BETWEEN -0.07236589155542399 AND 0.07236589155542399 AND items.longitude BETWEEN -0.07236589155542399 AND 0.07236589155542399) 在哪里(items.latitude在-0.07236589155542399和0.07236589155542399和items.longitude在-0.07236589155542399和0.07236589155542399之间)

Those upper and lower limits on latitude/longitude represent a small area off the western coast of Africa, so I'm not surprised that none of your items are located there. 纬度/经度的那些上限和下限代表了非洲西部沿海地区的一小片区域,因此,对于您的任何items都没有放在那里,我并不感到惊讶。

What values are being returned by location_info = request.location ? location_info = request.location返回什么值? Also, did you see this section from the documentation ? 另外,您是否从文档中看到此部分?

Note that these methods will usually return nil in your test and development environments because things like "localhost" and "0.0.0.0" are not an Internet IP addresses. 请注意,这些方法通常在您的测试和开发环境中返回nil,因为“ localhost”和“ 0.0.0.0”之类的东西不是Internet IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM