Module: ActsAsGeocodable::Model::InstanceMethods
- Defined in:
- lib/acts_as_geocodable.rb
Instance Method Summary collapse
-
#distance_to(destination, options = {}) ⇒ Object
Get the distance to the given destination.
-
#geocode ⇒ Object
Get the geocode for this model.
-
#to_location ⇒ Object
Create a Graticule::Location.
Instance Method Details
#distance_to(destination, options = {}) ⇒ Object
Get the distance to the given destination. The destination can be an acts_as_geocodable model, a Geocode, or a string
myhome.distance_to "Chicago, IL"
myhome.distance_to "49423"
myhome.distance_to other_model
Options
-
:units
::miles
or:kilometers
-
:formula
: The formula to use to calculate the distance. This can be any formula supported by Graticule. The default is:haversine
.
202 203 204 205 206 207 208 |
# File 'lib/acts_as_geocodable.rb', line 202 def distance_to(destination, = {}) units = [:units] || [:units] formula = [:formula] || :haversine geocode = self.class.location_to_geocode(destination) self.geocode.distance_to(geocode, units, formula) end |
#geocode ⇒ Object
Get the geocode for this model
177 178 179 |
# File 'lib/acts_as_geocodable.rb', line 177 def geocode geocoding.geocode if geocoding end |
#to_location ⇒ Object
Create a Graticule::Location
182 183 184 185 186 187 188 |
# File 'lib/acts_as_geocodable.rb', line 182 def to_location Graticule::Location.new.tap do |location| [:street, :locality, :region, :postal_code, :country].each do |attr| location.send "#{attr}=", geo_attribute(attr) end end end |