特定の投稿記録から離れたマイル数を取得しようとしています...
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
私は何を間違っていますか?