我正在尝试使用geokit找到一组给定坐标旁边的所有实体,我现在已经尝试了几个小时,似乎无法找到问题所在。
最初认为它与Latitude和Longitude列是String有关,所以只需运行迁移将它们转换为this指南后的Decimal,但没有运气,因为我仍然得到以下异常。
这是我的模特:
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))
有人可以帮忙吗? 谢谢!
答案 0 :(得分:0)
好的,太棒了!
所以,做一些测试,似乎由于某种原因,geokit不喜欢SQLite。 此外,我将更改回滚到十进制,它也可以工作,这意味着如果您的纬度和经度字段是字符串,则无关紧要。