geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different calculate values for ".within" method

hoppergee opened this issue · comments

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:

  • 78.06486321137547 under MysQL with ActiveRecord
  • 78.0648632113755 under Postgres with ActiveRecord