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:
Pythagorean Theory (flat Earth) - which assumes the world is flat and loses accuracy over long distances.
Haversine (sphere) - which is fairly accurate, but at a performance cost.
Distance units supported are :miles, :kms, and :nms.
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 201 def distance_to(other, options={}) self.class.distance_between(self, other, options) end
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 221 def endpoint(heading,distance,options={}) self.class.endpoint(self,heading,distance,options) end
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 214 def heading_from(other) self.class.heading_between(other,self) end
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 208 def heading_to(other) self.class.heading_between(self,other) end
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 228 def midpoint_to(other, options={}) self.class.midpoint_between(self,other,options) end
Extracts a LatLng instance. Use with models that are acts_as_mappable
# File lib/geokit/mappable.rb, line 191 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
Generated with the Darkfish Rdoc Generator 2.