Class: LatLong::Point
- Inherits:
-
Object
- Object
- LatLong::Point
- Defined in:
- lib/lat_long/point.rb
Constant Summary collapse
- ARGUMENT_ERRORS_TEXT =
{ direction: 'direction argument is not supported, use any of the following ' + DIRECTION_MULTIPLIERS.keys.join(', '), distance_unit: 'distance unit argument not supported, use any of the following ' + TO_METERS_MULTIPLIERS.keys.join(', '), }.freeze
Instance Attribute Summary collapse
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
Instance Method Summary collapse
-
#initialize(lat, long) ⇒ Point
constructor
A new instance of Point.
- #move(raw_distance, unit, direction) ⇒ Object
- #starting_point ⇒ Object
Constructor Details
#initialize(lat, long) ⇒ Point
Returns a new instance of Point.
14 15 16 17 |
# File 'lib/lat_long/point.rb', line 14 def initialize(lat, long) @lat = lat @long = long end |
Instance Attribute Details
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
12 13 14 |
# File 'lib/lat_long/point.rb', line 12 def lat @lat end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
12 13 14 |
# File 'lib/lat_long/point.rb', line 12 def long @long end |
Instance Method Details
#move(raw_distance, unit, direction) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lat_long/point.rb', line 23 def move(raw_distance, unit, direction) direction = direction_multipliers(direction) distance = distance_in_meters(raw_distance, unit) lat_offset = distance / EARTH_RADIUS long_offset = distance / ( EARTH_RADIUS * Math.cos(Math::PI * @lat/180) ) new_point_lat = @lat + (lat_offset * 180/Math::PI) * direction[:y_axis] new_point_long = @long + (long_offset * 180/Math::PI) * direction[:x_axis] { lat: new_point_lat, long: new_point_long } end |
#starting_point ⇒ Object
19 20 21 |
# File 'lib/lat_long/point.rb', line 19 def starting_point [@lat, @long] end |