Method: Hillpace::TrackPoint#distance_meters_to

Defined in:
lib/hillpace/track_point.rb

#distance_meters_to(other) ⇒ Number

Measures the distance to other track point, in meters.

Parameters:

  • other (TrackPoint)

    The other track point to compare.

Returns:

  • (Number)

Raises:

  • (RuntimeError)

    if other is not a TrackPoint object



80
81
82
83
84
85
# File 'lib/hillpace/track_point.rb', line 80

def distance_meters_to(other)
  raise 'Invalid track point' unless other.is_a? TrackPoint
  a = Geokit::GeoLoc.new({:lat => latitude, :lng => longitude})
  b = Geokit::GeoLoc.new({:lat => other.latitude, :lng => other.longitude})
  METERS_PER_KILOMETER * (a.distance_to b, {:units => :kms})
end