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

Units option to within method doesn't seems to properly work #121

Open rmagnum2002 opened 7 years ago

rmagnum2002 commented 7 years ago

I am trying to find objects in range of 4 kms, so I am using this example in docs:

Location.within(5, :units => :kms, :origin => @somewhere)
# it will get the records within 5 kilometers instead of 5 miles

in my case it will be: venues = Venue.within(4, units: :kms, origin: [44.1133355, -79.376071])

Also, to make sure it shows proper results, I am using this route as reference: https://www.google.com/maps/dir/44.088102,-79.3346276/19619+McCowan+Rd,+Mount+Albert,+ON+L0G+1M0,+Canada/@44.1132739,-79.3760709,13z/data=!3m1!4b1!4m8!4m7!1m0!1m5!1m1!1s0x89d534903b40df85:0x3a15c399937141ab!2m2!1d-79.3473307!2d44.1384912 it shows 5.7 km from origin to destination.

Now, the above venue should not be listed, as it is not in range of 4 km from origin, but actually it is listed. I've tried to narrow the distance to see at what point this venue will not be listed, and I got to:

venues = Venue.within(3.6, units: :kms, origin: [44.1133355, -79.376071])

Now, 3.6 miles to kms = 5.79364... and venue is not listed. This makes me think that within method ignores the units option and uses miles as units.

My setup:

  acts_as_mappable default_units: :kms,
                   lat_column_name: :latitude,
                   lng_column_name: :longitude,
                   default_formula: :sphere

Thank you.