"undefined method `/' for "":String:" 执行geokit时出错

"undefined method `/' for "":String:" Error when implementing geokit

我正在尝试使用 geokit 查找给定坐标集旁边的所有实体,我已经尝试了好几个小时,但似乎找不到问题所在。

最初认为这与纬度和经度列是字符串有关,所以只是 运行 按照 this 指南将它们转换为十进制的迁移,但没有像我这样的运气仍然收到以下异常。

这是我的模型:

class Video < ActiveRecord::Base
  include Rails.application.routes.url_helpers
  include ActiveModel::Dirty

  belongs_to :user
  belongs_to :camera
  belongs_to :lens
  belongs_to :airframe
  belongs_to :codec
  belongs_to :video_format
  belongs_to :updated_by, :class_name => "User"

  attr_accessible :duration, :location, :user_id, :camera_id, :lens_id, :video_format_id, 
                  :codec_id, :title, :description, :source_filename, 
                  :latitude, :longitude, :airframe_id, :resolution, :framerate, :bitrate,
                  :recording_datetime, :permissions, :source_video, :status, :terms_and_conditions, 
                  :updated_by_id, :video_tags_attributes, :staff_pick, :gallery_id

  acts_as_mappable :lat_column_name => :latitude,
                   :lng_column_name => :longitude

end

我的控制器的操作:

def index_by_location
    origin = Geokit::LatLng.new(32.91663,-96.982841)
    #origin = Video.geo_scope(:origin => [37.792,-122.393]) does not work
    videos = Video.in_range(2..5, :origin => origin)
    render :json => videos
  end

这是我遇到的错误:

 NoMethodError: undefined method `/' for "":String: SELECT "videos".* FROM "videos"  WHERE ((
          (CASE WHEN videos.latitude IS NULL OR videos.longitude IS NULL THEN NULL ELSE
          (ACOS(least(1,COS(0.5745035721607411)*COS(-1.6926698933881499)*COS(RADIANS(videos.latitude))*COS(RADIANS(videos.longitude))+
          COS(0.5745035721607411)*SIN(-1.6926698933881499)*COS(RADIANS(videos.latitude))*SIN(RADIANS(videos.longitude))+
          SIN(0.5745035721607411)*SIN(RADIANS(videos.latitude))))*3963.1899999999996)
          END)
          >= 2 AND 
          (CASE WHEN videos.latitude IS NULL OR videos.longitude IS NULL THEN NULL ELSE
          (ACOS(least(1,COS(0.5745035721607411)*COS(-1.6926698933881499)*COS(RADIANS(videos.latitude))*COS(RADIANS(videos.longitude))+
          COS(0.5745035721607411)*SIN(-1.6926698933881499)*COS(RADIANS(videos.latitude))*SIN(RADIANS(videos.longitude))+
          SIN(0.5745035721607411)*SIN(RADIANS(videos.latitude))))*3963.1899999999996)
          END)
          <= 5))

有人可以帮忙吗? 谢谢!

好的,太棒了!

所以,做了一些测试,似乎出于某种原因 geokit 不喜欢 SQLite。 此外,我将更改回滚到十进制并且它也可以正常工作,这意味着无论您的纬度和经度字段是否为字符串都没有关系。