Module: Geocoder::Store::Base
- Included in:
- ActiveRecord, MongoMapper, Mongoid
- Defined in:
- lib/geocoder/stores/base.rb
Instance Method Summary collapse
-
#bearing_from(point, options = {}) ⇒ Object
Calculate the bearing from another point to the object.
-
#bearing_to(point, options = {}) ⇒ Object
Calculate the bearing from the object to another point.
-
#distance_to(point, units = nil) ⇒ Object
(also: #distance_from)
Calculate the distance from the object to an arbitrary point.
-
#geocode ⇒ Object
Look up coordinates and assign to
latitude
andlongitude
attributes (or other as specified ingeocoded_by
). -
#geocoded? ⇒ Boolean
Is this object geocoded? (Does it have latitude and longitude?).
-
#reverse_geocode ⇒ Object
Look up address and assign to
address
attribute (or other as specified inreverse_geocoded_by
). -
#to_coordinates ⇒ Object
Coordinates [lat,lon] of the object.
Instance Method Details
#bearing_from(point, options = {}) ⇒ Object
Calculate the bearing from another point to the object. See Geocoder::Calculations.distance_between for ways of specifying the point.
51 52 53 54 55 56 |
# File 'lib/geocoder/stores/base.rb', line 51 def bearing_from(point, = {}) [:method] ||= self.class.[:method] return nil unless geocoded? Geocoder::Calculations.bearing_between( point, to_coordinates, ) end |
#bearing_to(point, options = {}) ⇒ Object
Calculate the bearing from the object to another point. See Geocoder::Calculations.distance_between for ways of specifying the point.
39 40 41 42 43 44 |
# File 'lib/geocoder/stores/base.rb', line 39 def bearing_to(point, = {}) [:method] ||= self.class.[:method] return nil unless geocoded? Geocoder::Calculations.bearing_between( to_coordinates, point, ) end |
#distance_to(point, units = nil) ⇒ Object Also known as: distance_from
Calculate the distance from the object to an arbitrary point. See Geocoder::Calculations.distance_between for ways of specifying the point. Also takes a symbol specifying the units (:mi or :km; can be specified in Geocoder configuration).
25 26 27 28 29 30 |
# File 'lib/geocoder/stores/base.rb', line 25 def distance_to(point, units = nil) units ||= self.class.[:units] return nil unless geocoded? Geocoder::Calculations.distance_between( to_coordinates, point, :units => units) end |
#geocode ⇒ Object
Look up coordinates and assign to latitude
and longitude
attributes (or other as specified in geocoded_by
). Returns coordinates (array).
62 63 64 |
# File 'lib/geocoder/stores/base.rb', line 62 def geocode fail end |
#geocoded? ⇒ Boolean
Is this object geocoded? (Does it have latitude and longitude?)
8 9 10 |
# File 'lib/geocoder/stores/base.rb', line 8 def geocoded? to_coordinates.compact.size > 0 end |
#reverse_geocode ⇒ Object
Look up address and assign to address
attribute (or other as specified in reverse_geocoded_by
). Returns address (string).
70 71 72 |
# File 'lib/geocoder/stores/base.rb', line 70 def reverse_geocode fail end |
#to_coordinates ⇒ Object
Coordinates [lat,lon] of the object.
15 16 17 |
# File 'lib/geocoder/stores/base.rb', line 15 def to_coordinates [:latitude, :longitude].map{ |i| send self.class.[i] } end |