class GpsUtils::Point
Attributes
lat[R]
@!attribute [r] lat
@return [Float, Integer] Latitude
lng[R]
@!attribute [r] lng
@return [Float, Integer] Longitude
Public Class Methods
new(lat, lng)
click to toggle source
Initialize Point
.
@param lat [Integer, Float] Latitude @param lng [Integer, Float] Langitude
# File lib/gpsutils.rb, line 21 def initialize(lat, lng) unless lat.is_a? Float or lat.is_a? Integer raise ArgumentError.new 'lat must be float or integer.' end unless lng.is_a? Float or lng.is_a? Integer raise ArgumentError.new 'lng must be float or integer.' end @lat = lat @lng = lng end
Public Instance Methods
distance(other)
click to toggle source
Measure the distance between this point and another.
Distance is calculated using equirectangular projection. @see en.wikipedia.org/wiki/Equirectangular_projection
@param other [Point] @return [Float] @raise [ArgumentError] if other is not a Point
# File lib/gpsutils.rb, line 52 def distance(other) unless other.is_a? Point raise ArgumentError.new 'other must be a Point.' end dlng = GpsUtils::to_radians(other.lng - @lng) dlat = GpsUtils::to_radians(other.lat - @lat) x = dlng * Math.cos(dlat / 2) y = GpsUtils::to_radians(other.lat - @lat) Math.sqrt(x**2 + y**2) * GpsUtils::R end
to_a()
click to toggle source
@return [Array] Array with latitude and longitude as Float or Integer
values, as used when object was initialized
# File lib/gpsutils.rb, line 36 def to_a [@lat, @lng] end
to_s()
click to toggle source
# File lib/gpsutils.rb, line 40 def to_s "#{@lat},#{@lng}" end