| Module | GeoKit::Mappable |
| In: |
vendor/plugins/geokit/lib/geo_kit/mappable.rb
|
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 and :kms.
| PI_DIV_RAD | = | 0.0174 |
| KMS_PER_MILE | = | 1.609 |
| EARTH_RADIUS_IN_MILES | = | 3963.19 |
| EARTH_RADIUS_IN_KMS | = | EARTH_RADIUS_IN_MILES * KMS_PER_MILE |
| MILES_PER_LATITUDE_DEGREE | = | 69.1 |
| KMS_PER_LATITUDE_DEGREE | = | MILES_PER_LATITUDE_DEGREE * KMS_PER_MILE |
| LATITUDE_DEGREES | = | EARTH_RADIUS_IN_MILES / MILES_PER_LATITUDE_DEGREE |
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 or :kms (:miles is the default) :formula - valid values are :flat or :sphere (:sphere is the default)
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 154
154: def distance_to(other, options={})
155: self.class.distance_between(self, other, options)
156: end
Returns the endpoint, given a heading (in degrees) and distance. Valid option: :units - valid values are :miles or :kms (:miles is the default)
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 174
174: def endpoint(heading,distance,options={})
175: self.class.endpoint(self,heading,distance,options)
176: 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 vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 167
167: def heading_from(other)
168: self.class.heading_between(other,self)
169: 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 vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 161
161: def heading_to(other)
162: self.class.heading_between(self,other)
163: end
Returns the midpoint, given another point on the map. Valid option: :units - valid values are :miles or :kms (:miles is the default)
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 181
181: def midpoint_to(other, options={})
182: self.class.midpoint_between(self,other,options)
183: end
Extracts a LatLng instance. Use with models that are acts_as_mappable
# File vendor/plugins/geokit/lib/geo_kit/mappable.rb, line 144
144: def to_lat_lng
145: return self if instance_of?(GeoKit::LatLng) || instance_of?(GeoKit::GeoLoc)
146: return LatLng.new(send(self.class.lat_column_name),send(self.class.lng_column_name)) if self.class.respond_to?(:acts_as_mappable)
147: return nil
148: end