Module: CollectiveIdea::Acts::Geocodable::InstanceMethods
- Defined in:
- lib/acts_as_geocodable.rb
Instance Method Summary collapse
- #attach_geocode_now ⇒ Object
- #attach_geocode_with_delay ⇒ Object
-
#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
#attach_geocode_now ⇒ Object
259 260 261 |
# File 'lib/acts_as_geocodable.rb', line 259 def attach_geocode_now attach_geocode end |
#attach_geocode_with_delay ⇒ Object
263 264 265 |
# File 'lib/acts_as_geocodable.rb', line 263 def attach_geocode_with_delay self.send_later :attach_geocode end |
#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
.
251 252 253 254 255 256 257 |
# File 'lib/acts_as_geocodable.rb', line 251 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
226 227 228 |
# File 'lib/acts_as_geocodable.rb', line 226 def geocode geocoding.geocode if geocoding end |
#to_location ⇒ Object
Create a Graticule::Location
231 232 233 234 235 236 237 |
# File 'lib/acts_as_geocodable.rb', line 231 def to_location returning Graticule::Location.new do |location| [:street, :locality, :region, :postal_code, :country].each do |attr| location.send "#{attr}=", geo_attribute(attr) end end end |