我正在尝试使用 geokit 来查找给定坐标集旁边的所有实体,我已经尝试了几个小时,但似乎无法找到问题所在。
最初认为这与作为字符串的纬度和经度列有关,所以只需按照此指南运行迁移以将它们转换为十进制,但没有运气,因为我仍然遇到以下异常。
这是我的模型:
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))
有人可以帮忙吗?谢谢!