module Geocoder::Store::Base

Public Instance Methods

bearing_from(point, options = {}) click to toggle source

Calculate the bearing from another point to the object. See Geocoder::Calculations.distance_between for ways of specifying the point.

# File lib/geocoder/stores/base.rb, line 51
def bearing_from(point, options = {})
  options[:method] ||= self.class.geocoder_options[:method]
  return nil unless geocoded?
  Geocoder::Calculations.bearing_between(
    point, to_coordinates, options)
end
bearing_to(point, options = {}) click to toggle source

Calculate the bearing from the object to another point. See Geocoder::Calculations.distance_between for ways of specifying the point.

# File lib/geocoder/stores/base.rb, line 39
def bearing_to(point, options = {})
  options[:method] ||= self.class.geocoder_options[:method]
  return nil unless geocoded?
  Geocoder::Calculations.bearing_between(
    to_coordinates, point, options)
end
distance_from(point, units = nil)
Alias for: distance_to
distance_to(point, units = nil) click to toggle source

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).

# File lib/geocoder/stores/base.rb, line 25
def distance_to(point, units = nil)
  units ||= self.class.geocoder_options[:units]
  return nil unless geocoded?
  Geocoder::Calculations.distance_between(
    to_coordinates, point, :units => units)
end
Also aliased as: distance_from
geocode() click to toggle source

Look up coordinates and assign to latitude and longitude attributes (or other as specified in geocoded_by). Returns coordinates (array).

# File lib/geocoder/stores/base.rb, line 62
def geocode
  fail
end
geocoded?() click to toggle source

Is this object geocoded? (Does it have latitude and longitude?)

# File lib/geocoder/stores/base.rb, line 8
def geocoded?
  to_coordinates.compact.size == 2
end
reverse_geocode() click to toggle source

Look up address and assign to address attribute (or other as specified in reverse_geocoded_by). Returns address (string).

# File lib/geocoder/stores/base.rb, line 70
def reverse_geocode
  fail
end
to_coordinates() click to toggle source

Coordinates [lat,lon] of the object.

# File lib/geocoder/stores/base.rb, line 15
def to_coordinates
  [:latitude, :longitude].map{ |i| send self.class.geocoder_options[i] }
end