Geocoder,s gem near 方法不适用于 rails 5

Geocoder,s gem near method not working on rails 5

一直在尝试使用地理编码器 gem 来查找位置,使用附近的地理编码器方法来查找特定点附近的特定位置。

def index
  @data = Datum.all

   @emergency = Emergency.last
   @data_near = Datum.near([@emergency.longitude,@emergency.latitude],100,:units => :km)

  @geojson = Array.new

  @data_near.each do |mapdata|
     @geojson << {
          type: 'Feature',
          geometry: {
            type: 'Point',
            coordinates: [mapdata.longitude, mapdata.latitude]
          },
          properties: {
            name: mapdata.description,
            address: mapdata.address,
            BusType: 'hospital',
            popupContent: "#{mapdata.address} is a #{mapdata.description}",
            :'marker-color' => '#00607d',
            :'marker-symbol' => 'circle',
            :'marker-size' => 'medium'
          }
        }
  end
  respond_to do |format|
     format.html
     format.json{ render json: @geojson }
  end

结束

这就是我正在尝试 运行 的代码,它 returns 是一个空数组,即使存在指定参数附近的位置也是如此。当我尝试 运行 直接在 rails 控制台中使用真正的 points.eg.

代码时
data = Datum.near([36.7689503,-1.381776],10,:units => :km)

我没有收到任何错误,但我得到的输出不太可读或 comprehensible.The 输出是:

Datum Load (0.3ms)  SELECT  data.*, (111.19492664455873 * ABS(data.latitude - 36.7689503) * 0.7071067811865475) + (96.29763124613503 * ABS(data.longitude - -1.381776) * 0.7071067811865475) AS distance, CASE WHEN (data.latitude >= 36.7689503 AND data.longitude >= -1.381776) THEN  45.0 WHEN (data.latitude <  36.7689503 AND data.longitude >= -1.381776) THEN 135.0 WHEN (data.latitude <  36.7689503 AND data.longitude <  -1.381776) THEN 225.0 WHEN (data.latitude >= 36.7689503 AND data.longitude <  -1.381776) THEN 315.0 END AS bearing FROM "data" WHERE (data.latitude BETWEEN 36.67901813940813 AND 36.85888246059187 AND data.longitude BETWEEN -1.4940430256783075 AND -1.2695089743216923) ORDER BY distance ASC LIMIT ?  [["LIMIT", 11]]




 => #<ActiveRecord::Relation []> 

任何帮助将不胜感激。

t.string "longitude"
t.string "latitude"

用错误的字符串数据类型在数据库中保存了我的坐标,坐标应该用浮点数据保存attribute.This为可能遇到相同问题的任何人解决了我的问题problem.Its 开始检查的好地方。