examples/ruby/route_guide/route_guide_server.rb
# Determines the distance between two points.
Determines the distance between two points.
Determines the distance between two points .
def calculate_distance(point_a, point_b)
  to_radians = proc { |x| x * Math::PI / 180 }
  lat_a = point_a.latitude / COORD_FACTOR
  lat_b = point_b.latitude / COORD_FACTOR
  long_a = point_a.longitude / COORD_FACTOR
  long_b = point_b.longitude / COORD_FACTOR
  φ1 = to_radians.call(lat_a)
  φ2 = to_radians.call(lat_b)
  Δφ = to_radians.call(lat_a - lat_b)
  Δλ = to_radians.call(long_a - long_b)
  a = Math.sin(Δφ / 2)**2 +
      Math.cos(φ1) * Math.cos(φ2) +
      Math.sin(Δλ / 2)**2
  (2 * RADIUS *  Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))).to_i
end
def calculate_distance ( point_a , point_b ) to_radians = proc { | x | x * Math :: PI / 180 } lat_a = point_a . latitude / COORD_FACTOR lat_b = point_b . latitude / COORD_FACTOR long_a = point_a . longitude / COORD_FACTOR long_b = point_b . longitude / COORD_FACTOR φ1  o_radians. c all( l at_a) φ2  o_radians. c all( l at_b) Δφ = t _radians.c a ll(l a t_a - l t_b) Δλ = t _radians.c a ll(l o ng_a - l ng_b) a = Math . sin ( Δφ / 2 * * 2  + Math . cos ( φ1) ath. c os( φ 2)  + Math . sin ( Δλ / 2 * * 2 ( 2 * RADIUS * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ) . to_i end
Determines the distance between two points.
Determines the distance between two points .
point_a
point_b