我试图让英里远特定职位记录的数量...为什么我的rgeo/postgis与现实距离太远了?
class Post < ActiveRecord::Base
attr_accessor :lat, :lng
set_rgeo_factory_for_column(:location, RGeo::Geographic.spherical_factory(:srid => 4326))
def distance_from(current_location)
rgeo_factory.point(current_location[:lng], current_location[:lat]).distance(location)/1.60934
end
private
def update_location!
self.location = rgeo_factory.point(lng, lat) if lat && lng
end
def rgeo_factory
Post.rgeo_factory_for_column(:location)
end
end
如果我创建内华达州拉斯维加斯的位置后(纬度:36.255123,经度:-115.238348)我确认它 -
1.9.3p125 :018 > p.lat = 36.255123
=> 36.255123
1.9.3p125 :019 > p.lng = -115.238348
=> -115.238348
1.9.3p125 :019 > p
#<Post id: 133, location: #<RGeo::Geographic::SphericalPointImpl:0x81d7130c "POINT (-115.238348 36.255123)">
当我试图获得该职位,并在加利福尼亚州一个点之间的距离,我得到英里一个疯狂的数量...
1.9.3p125 :027 > p.distance_from(:lat => 34.019454, :lng => -118.491191)
=> 240327.390598477
我在做什么错误?