Sha256: ad5139fa7279f44001339724dee7f168fe239c772760f8a4db0411acaad2a75f
Contents?: true
Size: 804 Bytes
Versions: 1
Compression:
Stored size: 804 Bytes
Contents
# Extends AR to add earthdistance functionality. module ActiveRecord class Base def self.acts_as_geolocated(options = {}, distances = {}) @@latitude_column = options[:lat] @@longitude_column = options[:lng] @@latitude_column = (column_names.include?("lat") ? "lat" : "latitude") unless @@latitude_column @@longitude_column = (column_names.include?("lng") ? "lng" : "longitude") unless @@longitude_column def self.within_radius radius, lat, lng, unit = :meters where(["ll_to_earth(#{@@latitude_column}, #{@@longitude_column}) <@ earth_box(ll_to_earth(?, ?), ?) AND earth_distance(ll_to_earth(#{@@latitude_column}, #{@@longitude_column}), ll_to_earth(?, ?)) <= ?", lat, lng, radius, lat, lng, radius]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-postgres-earthdistance-0.1.0 | lib/activerecord-postgres-earthdistance/activerecord.rb |