Geokit::Mappable

Contains class and instance methods providing distance calcuation services. This module is meant to be mixed into classes containing lat and lng attributes where distance calculation is desired.

At present, two forms of distance calculations are provided:

Distance units supported are :miles, :kms, and :nms.

Public Instance Methods

distance_from(other, options={}) click to toggle source
Alias for: distance_to
distance_to(other, options={}) click to toggle source

Returns the distance from another point. The other point parameter is required to have lat and lng attributes. Valid options are: :units - valid values are :miles, :kms, :or :nms (:miles is the default) :formula - valid values are :flat or :sphere (:sphere is the default)

# File lib/geokit/mappable.rb, line 190
def distance_to(other, options={})
  self.class.distance_between(self, other, options)
end
Also aliased as: distance_from
endpoint(heading,distance,options={}) click to toggle source

Returns the endpoint, given a heading (in degrees) and distance. Valid option: :units - valid values are :miles, :kms, or :nms (:miles is the default)

# File lib/geokit/mappable.rb, line 210
def endpoint(heading,distance,options={})
  self.class.endpoint(self,heading,distance,options)
end
heading_from(other) click to toggle source

Returns heading in degrees (0 is north, 90 is east, 180 is south, etc) FROM the given point. The given point can be a LatLng or a string to be Geocoded

# File lib/geokit/mappable.rb, line 203
def heading_from(other)
  self.class.heading_between(other,self)
end
heading_to(other) click to toggle source

Returns heading in degrees (0 is north, 90 is east, 180 is south, etc) to the given point. The given point can be a LatLng or a string to be Geocoded

# File lib/geokit/mappable.rb, line 197
def heading_to(other)
  self.class.heading_between(self,other)
end
midpoint_to(other, options={}) click to toggle source

Returns the midpoint, given another point on the map. Valid option: :units - valid values are :miles, :kms, or :nms (:miles is the default)

# File lib/geokit/mappable.rb, line 217
def midpoint_to(other, options={})
  self.class.midpoint_between(self,other,options)
end
to_lat_lng() click to toggle source

Extracts a LatLng instance. Use with models that are acts_as_mappable

# File lib/geokit/mappable.rb, line 180
def to_lat_lng
  return self if instance_of?(Geokit::LatLng) || instance_of?(Geokit::GeoLoc)
  return LatLng.new(send(self.class.lat_column_name), send(self.class.lng_column_name))
  nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.