geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

Different calculate values for ".within" method #154

Closed hoppergee closed 3 years ago

hoppergee commented 4 years ago
SELECT
(ACOS(least(1,COS(0.5410520681182421)*COS(0.5061454830783556)*COS(RADIANS(31.15))*COS(RADIANS(29.8))+COS(0.5410520681182421)*SIN(0.5061454830783556)*COS(RADIANS(31.15))*SIN(RADIANS(29.8))+SIN(0.5410520681182421)*SIN(RADIANS(31.15))))*6376.77271) AS distance;

This query get same result 78.06486321137547 under MySQL and PostgreSQL.

But when I use ActiveRecord to do this query:

ActiveRecord::Base.connection.execute("SELECT (ACOS(least(1,COS(0.5410520681182421)*COS(0.5061454830783556)*COS(RADIANS(31.15))*COS(RADIANS(29.8))+COS(0.5410520681182421)*SIN(0.5061454830783556)*COS(RADIANS(31.15))*SIN(RADIANS(29.8))+SIN(0.5410520681182421)*SIN(RADIANS(31.15))))*6376.77271) AS distance")

I get different resutls: